package com.jwsoft.manager.core.integration.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdcardUtil;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bifang.assistant.common.vo.BaseVO;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.annotation.SaveOplog;
import com.bifang.engine.assistant.core.enums.AuTypeEnum;
import com.bifang.engine.assistant.core.enums.AuthStatusEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.assistant.core.utils.SessionUtil;
import com.bifang.engine.cache.redis.RedisHelper;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.module.base.common.util.ApplicationContextHelper;
import com.bifang.module.base.common.util.CommonSecureUtil;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.common.vo.dict.DictAreaVO;
import com.bifang.module.base.common.vo.dict.DictQueryVO;
import com.bifang.module.base.common.vo.dict.DictVO;
import com.bifang.module.base.common.vo.dict.SelectVO;
import com.bifang.module.base.core.helper.ApiModel;
import com.bifang.module.base.core.helper.DictHelper;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.bifang.module.base.core.integration.DictIntegration;
import com.bifang.module.base.core.integration.OperationPeriodIntegration;
import com.bifang.module.system.common.enums.CardTypeEnum;
import com.bifang.module.system.core.dao.model.PersonInfo;
import com.bifang.module.system.core.dao.service.PersonInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.constant.EduCache;
import com.jwsoft.manager.common.enums.*;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheDetailVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheVO;
import com.jwsoft.manager.common.vo.eduAppointStudent.EduAppointStudentVO;
import com.jwsoft.manager.common.vo.eduCompany.EduCompanyVO;
import com.jwsoft.manager.common.vo.eduFormSpecial.EduFormSpecialQueryVO;
import com.jwsoft.manager.common.vo.eduFormSpecial.EduFormSpecialVO;
import com.jwsoft.manager.common.vo.eduHouse.EduHousePreVO;
import com.jwsoft.manager.common.vo.eduHouse.EduHouseVO;
import com.jwsoft.manager.common.vo.eduHouseDetail.EduHouseDetailVO;
import com.jwsoft.manager.common.vo.eduHousehold.EduHouseholdVO;
import com.jwsoft.manager.common.vo.eduLivePlace.EduLivePlaceVO;
import com.jwsoft.manager.common.vo.eduNetsign.EduNetsignVO;
import com.jwsoft.manager.common.vo.eduPrivateAppointStudent.EduPrivateAppointStudentVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolVO;
import com.jwsoft.manager.common.vo.eduSocialSecurity.EduSocialSecurityVO;
import com.jwsoft.manager.common.vo.eduStudentEnroll.EduStudentEnrollVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollBefore.*;
import com.jwsoft.manager.common.vo.eduStudentEnrollFamily.EduStudentEnrollFamilyVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreKeyVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreQueryVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreVO;
import com.jwsoft.manager.common.vo.eduStudentStatus.EduStudentStatusVO;
import com.jwsoft.manager.common.vo.eduhStudentEnroll.EduhStudentEnrollVO;
import com.jwsoft.manager.common.vo.eduhStudentEnrollPre.EduhStudentEnrollPreVO;
import com.jwsoft.manager.common.vo.individuation.*;
import com.jwsoft.manager.core.dao.model.*;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.*;
import com.jwsoft.manager.core.util.EduEnrollClearCacheHelper;
import com.jwsoft.manager.core.util.EduHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 义务教育阶段预报名表业务实现类
 *
 * @author wangtao
 * @since 2022-12-13
 */
@ApiService(funcCode = "eduStudentEnrollBefore", title = "义务教育阶段预报名表")
@Slf4j
public class EduStudentEnrollBeforeIntegrationImpl implements EduStudentEnrollBeforeIntegration {
    @Autowired
    public EduStudentEnrollBeforeService eduStudentEnrollBeforeService;

    @Resource
    OperationPeriodIntegration operationPeriodIntegration;
    @Autowired
    EduHelper eduHelper;
    @Autowired
    private RedisHelper redisHelper;
    @Autowired
    OperationCacheIntegration operationCacheIntegration;
    @Autowired
    EduSystemConfigIntegration eduSystemConfigIntegration;
    @Autowired
    EduStudentEnrollPreService eduStudentEnrollPreService;
    @Autowired
    EduhStudentEnrollPreService eduhStudentEnrollPreService;
    @Autowired
    EduSchoolVacancyService eduSchoolVacancyService;
    @Autowired
    private EduStudentEnrollFamilyService eduStudentEnrollFamilyService;
    @Autowired
    private EduSocialSecurityService eduSocialSecurityService;
    @Autowired
    private EduhSocialSecurityService eduhSocialSecurityService;
    @Autowired
    private EduCompanyService eduCompanyService;
    @Autowired
    private EduhCompanyService eduhCompanyService;
    @Autowired
    private EduSchoolService eduSchoolService;
    @Autowired
    private EduLivePlaceService eduLivePlaceService;
    @Autowired
    private EduhLivePlaceService eduhLivePlaceService;
    @Autowired
    private PersonInfoService personInfoService;

    @Autowired
    private EduHouseService eduHouseService;

    @Autowired
    private EduhHouseService eduhHouseService;
    @Autowired
    private EduNetsignService eduNetsignService;

    @Autowired
    private EduhNetsignService eduhNetsignService;

    @Autowired
    private EduHouseholdService eduHouseholdService;

    @Autowired
    private EduAppointStudentService eduAppointStudentService;

    @Autowired
    private EduPrivateAppointStudentService eduPrivateAppointStudentService;

    @Autowired
    private EduStudentEnrollService eduStudentEnrollService;
    @Autowired
    private EduStudentStatusService eduStudentStatusService;

    @Autowired
    private EduAreaService eduAreaService;
    @Autowired
    private DictHelper dictHelper;

    @Autowired
    private EduEnrollmenBrochureService eduEnrollmenBrochureService;
    @Autowired
    private EduNetsignIntegration eduNetsignIntegration;
    @Autowired
    private EduCompanyIntegration eduCompanyIntegration;
    @Autowired
    private EduSocialSecurityIntegration eduSocialSecurityIntegration;
    @Autowired
    private EduLivePlaceIntegration eduLivePlaceIntegration;
    @Autowired
    private EduEnrollClearCacheHelper eduEnrollClearCacheHelper;
    @Autowired
    private EduHouseholdIntegration eduHouseholdIntegration;
    @Autowired
    private EduHouseIntegration eduHouseIntegration;
    @Resource
    DictIntegration dictIntegration;
    @Autowired
    private CommonIntegration commonIntegration;
    @Autowired
    private EduHouseDetailService eduHouseDetailService;

    @Autowired
    private EduhHouseDetailService eduhHouseDetailService;

    @Autowired
    private EduFormSpecialService eduFormSpecialService;

    @Autowired
    private EduStudentEnrollPreIntegration eduStudentEnrollPreIntegration;

    @Autowired
    private EduDataTaskDetailService eduDataTaskDetailService;

    @Autowired
    private EduhHouseholdService eduhHouseholdService;

    @Autowired
    private EduhStudentEnrollService eduhStudentEnrollService;

    @Autowired
    public EduhStudentStatusService eduhStudentStatusService;
    public static final String handleTable = "edu_student_enroll_pre";
    public static final String handleTableHouse = "edu_house";
    public static final String handleTableHouseDetail = "edu_house_detail";
    public static final String handleTablehousehold = "edu_household";
    public static final String handleTableenroll = "edu_student_enroll";

    private final String createBatchBeforeCatch = "task:createBatchBeforeCatch";

    @Autowired
    private static final String STUDENT_ENROLL_PRE = "edu_student_enroll_pre";

    public static final String HOUSE_TABLE = "edu_house";
    public static final String HOUSE_TABLE_DETAIL = "edu_house_detail";
    public static final String HOUSEHOLD_TABLE = "edu_household";

    private static final String STUDENT_SOCIAL_SECURITY = "edu_social_security";
    private static final String EDU_NETSIGN = "edu_netsign";
    private static final String EDU_STUDENT_STATUS = "edu_student_status";
    private static final String EDU_COMPANY = "edu_company";
    private static final String EDU_LIVE_PLACE = "edu_live_place";

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0001", title = "义务教育阶段预报名表分页查询", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollBeforeVO> getList(EduStudentEnrollBeforeQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(1000);
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<EduStudentEnrollBefore> list = eduStudentEnrollBeforeService.list();
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        // 不为空则获取分页结果
        PageInfo<EduStudentEnrollBefore> pageInfo = new PageInfo<>(list);
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        List<EduStudentEnrollBeforeVO> resultList = Convert.toList(EduStudentEnrollBeforeVO.class, pageInfo.getList());
        // 转义数据字典值
        // dictHelper.valueToName(resultList, Arrays.asList(DemoDictEnum.values()));
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0002", title = "义务教育阶段预报名表根据主键查询详情", funcType = FuncTypeEnum.query)
    public EduStudentEnrollBeforeVO getById(EduStudentEnrollBeforeKeyVO vo) {
        EduStudentEnrollBefore entity = eduStudentEnrollBeforeService.getById(vo.getEnrollBeforeId());
        if (ObjectUtils.isEmpty(entity)) {
            throw new AppException("查询不到详细信息!");
        }
        EduStudentEnrollBeforeVO result = Convert.convert(EduStudentEnrollBeforeVO.class, entity);
        return result;
    }

    /**
     * 保存前统一校验
     */
    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0003", title = "义务教育阶段预报名表保存前校验", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void checkSave(EduStudentEnrollBeforeVO vo) {
        //主键为空为新增校验

        //主键不为空为修改校验
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0004", title = "义务教育阶段预报名表特殊通道新增", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "eduStudentEnrollBefore0004",
            operationName = "义务教育阶段预报名表特殊通道新增",
            dataType = "enrollBeforeId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentEnrollBeforeVO add(EduStudentEnrollBeforeVO vo) {

        if(StringUtils.isBlank(vo.getConfigName())){
            throw new AppException("特殊通道类别不能为空");
        }
        if(StringUtils.isBlank(vo.getConfigTypeName())){
            throw new AppException("特殊通道类别不能为空");
        }
        EduStudentEnrollPre pre = new EduStudentEnrollPre();

        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }

        if(StringUtils.isBlank(vo.getStudentEnrollPreId())){
          EduStudentEnrollPreVO  preVO = eduStudentEnrollPreIntegration.add(vo.getStudentEnrollPreVO());
          pre = Convert.convert(EduStudentEnrollPre.class,preVO);
        }else {
            pre = eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
            eduStudentEnrollPreIntegration.edit(vo.getStudentEnrollPreVO());
        }


        //保存数据
        EduStudentEnrollBefore entity = new EduStudentEnrollBefore();
        if(ObjectUtils.isEmpty(pre.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        entity.setYear(vo.getYear());
        entity.setStudentEnrollPreId(pre.getStudentEnrollPreId());
        if(StringUtils.isBlank(entity.getSchoolId())){
            entity.setSchoolId(SessionUtil.getOrgId());
        }
        EduSchoolVO eduSchool = eduSchoolService.getDetail(vo.getSchoolId());
        if (eduSchool == null) {
            throw new AppException("学校信息不存在");
        }
        //保存前校验
        QueryWrapper<EduStudentEnrollBefore> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentEnrollBefore::getYear, pre.getYear())
                .eq(EduStudentEnrollBefore::getSchoolId, entity.getSchoolId())
                .eq(EduStudentEnrollBefore::getStudentEnrollPreId, pre.getStudentEnrollPreId())
                .eq(EduStudentEnrollBefore::getSpecialFlag, BoolEnum.TRUE.getType());
        if (eduStudentEnrollBeforeService.count(queryWrapper) > 0) {
            throw new AppException("该人员特殊通道已存在");
        }
        entity.setAreaCode(eduSchool.getAreaCode());
        entity.setConfigName(vo.getConfigName());
        entity.setConfigTypeName(vo.getConfigTypeName());
        entity.setSpecialFlag(BoolEnum.TRUE.getType());
        entity.setAppointFlag(BoolEnum.FALSE.getType());
        entity.setPrivateAppointFlag(BoolEnum.FALSE.getType());
        entity.setAuthStatus(AuthStatusEnum.YES.getType());
        entity.setAuthTime(new Date());
        entity.setAuthUserId(SessionUtil.getUserId());
        entity.setHouseId(vo.getHouseId());
        entity.setAuthRemarks("学校特殊通道新增审核通过");
        entity.setHouseIdcard(vo.getHouseIdcard());
        entity.setHouseName(vo.getHouseName());
        entity.setRelationshipType(vo.getRelationshipType());
        EduFormSpecialQueryVO queryVO = new EduFormSpecialQueryVO();
        queryVO.setYear(entity.getYear());
        queryVO.setBigClassValue(entity.getConfigTypeName());
        queryVO.setSmallClassValue(entity.getConfigName());
        queryVO.setAreaCode(entity.getAreaCode());
        EduFormSpecialVO eduFormSpecialVO = eduFormSpecialService.getBySmallValue(queryVO);
        if (eduFormSpecialVO != null) {
            if (BoolEnum.TRUE.getType().equalsIgnoreCase(eduFormSpecialVO.getHouseFlag())) {
                if (StringUtils.isBlank(vo.getHouseId())) {
                    throw new AppException("房产不能为空");
                }
            }
        }
        if (StringUtils.isNotBlank(vo.getHouseId())) {
            EduHouse eduHouse = eduHouseService.getHouseById(vo.getHouseId());
            if (eduHouse == null) {
                throw new AppException("系统中未找到房产信息");
            }
            entity.setHouseAdreess(eduHouse.getAddress());
        }

        eduStudentEnrollBeforeService.save(entity);
        //将主键设置回vo使操作日志可以取到
        vo.setEnrollBeforeId(entity.getEnrollBeforeId());
        eduEnrollClearCacheHelper.clearCachePreBefore(entity.getStudentEnrollPreId());
        return vo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBeforeJh0004", title = "义务教育阶段预报名表特殊通道新增金华", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "eduStudentEnrollBeforeJh0004",
            operationName = "义务教育阶段预报名表特殊通道新增金华",
            dataType = "enrollBeforeId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentEnrollBeforeVO addJh(EduStudentEnrollBeforeVO vo) {

        if(StringUtils.isBlank(vo.getConfigTypeName())){
            throw new AppException("政策类别不能为空");
        }
        if(StringUtils.isBlank(vo.getSchoolId())){
            vo.setSchoolId(SessionUtil.getOrgId());
        }

        EduSchoolVO eduSchool = eduSchoolService.getDetail(vo.getSchoolId());
        if (eduSchool == null) {
            throw new AppException("学校信息不存在");
        }
        EduStudentEnrollPre pre = new EduStudentEnrollPre();

        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduSchool.getAreaCode());
        }

        if(StringUtils.isBlank(vo.getStudentEnrollPreId())){
            EduStudentEnrollPreVO  preVO = eduStudentEnrollPreIntegration.add(vo.getStudentEnrollPreVO());
            pre = Convert.convert(EduStudentEnrollPre.class,preVO);
        }else {
            pre = eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
            eduStudentEnrollPreIntegration.edit(vo.getStudentEnrollPreVO());
        }

        //保存数据
        EduStudentEnrollBefore entity = new EduStudentEnrollBefore();
        if(ObjectUtils.isEmpty(pre.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        entity.setYear(vo.getYear());
        entity.setStudentEnrollPreId(pre.getStudentEnrollPreId());
        entity.setSchoolId(vo.getSchoolId());
        //保存前校验
        QueryWrapper<EduStudentEnrollBefore> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentEnrollBefore::getYear, pre.getYear())
                .eq(EduStudentEnrollBefore::getSchoolId, entity.getSchoolId())
                .eq(EduStudentEnrollBefore::getStudentEnrollPreId, pre.getStudentEnrollPreId())
                .eq(EduStudentEnrollBefore::getSpecialFlag, BoolEnum.TRUE.getType());
        if (eduStudentEnrollBeforeService.count(queryWrapper) > 0) {
            throw new AppException("该人员已登记，不能重复登记");
        }
        entity.setAreaCode(eduSchool.getAreaCode());
        if(StringUtils.isBlank(vo.getConfigName())){
            LambdaQueryWrapper<EduFormSpecial> specialLambdaQueryWrapper=new LambdaQueryWrapper<>();
            specialLambdaQueryWrapper.eq(EduFormSpecial::getAreaCode,eduSchool.getAreaCode())
                    .eq(EduFormSpecial::getYear,vo.getYear())
                    .eq(EduFormSpecial::getBigClassValue,vo.getConfigTypeName());
            EduFormSpecial eduFormSpecial=eduFormSpecialService.getOne(specialLambdaQueryWrapper,false);
            if (eduFormSpecial!=null){
                entity.setConfigName(eduFormSpecial.getSmallClassValue());
                entity.setConfigNameAlias(eduFormSpecial.getSmallClassValue());
            }
        }else{
            entity.setConfigName(vo.getConfigName());
            entity.setConfigNameAlias(vo.getConfigName());
        }

        entity.setConfigTypeName(vo.getConfigTypeName());
        entity.setSpecialFlag(BoolEnum.TRUE.getType());
        entity.setAppointFlag(BoolEnum.FALSE.getType());
        entity.setPrivateAppointFlag(BoolEnum.FALSE.getType());
        entity.setAuthStatus(AuthStatusEnum.YES.getType());
        entity.setAuthTime(new Date());
        entity.setAuthUserId(SessionUtil.getUserId());
        entity.setHouseId(vo.getHouseId());
        entity.setAuthRemarks("政策性新增审核通过");
        entity.setHouseIdcard(vo.getHouseIdcard());
        entity.setHouseName(vo.getHouseName());
        entity.setRelationshipType(vo.getRelationshipType());


        eduStudentEnrollBeforeService.save(entity);
        //将主键设置回vo使操作日志可以取到
        vo.setEnrollBeforeId(entity.getEnrollBeforeId());
        eduEnrollClearCacheHelper.clearCachePreBefore(entity.getStudentEnrollPreId());
        return vo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0005", title = "义务教育阶段预报名表特殊通道修改", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollBefore0005",
            operationName = "义务教育阶段预报名表特殊通道修改",
            dataType = "enrollBeforeId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public StudentEnrollBeforeSaveVO edit(StudentEnrollBeforeSaveVO vo) {
        if (ObjectUtils.isEmpty(vo.getEnrollBeforeId())) {
            throw new AppException("传入需要修改的主键不能为空!");
        }
        if(StringUtils.isBlank(vo.getConfigName())){
            throw new AppException("特殊通道类别不能为空");
        }
        if(StringUtils.isBlank(vo.getConfigTypeName())){
            throw new AppException("特殊通道类别不能为空");
        }
        EduStudentEnrollBefore oldEntity = eduStudentEnrollBeforeService.getById(vo.getEnrollBeforeId());
        if (ObjectUtils.isEmpty(oldEntity)) {
            throw new AppException("查询不到需要修改的信息!");
        }

        eduStudentEnrollPreIntegration.edit(vo.getStudentEnrollPreVO());

        //保存数据
        if (StringUtils.isBlank(vo.getAuthStatus())) {
            vo.setAuthStatus(AuthStatusEnum.YES.getType());
            vo.setAuthRemarks("有权限的系统操作员修改");
        }
        oldEntity.setConfigTypeName(vo.getConfigTypeName());
        oldEntity.setConfigName(vo.getConfigName());
        oldEntity.setConfigNameAlias(vo.getConfigName());


        oldEntity.setHouseId(vo.getHouseId());
        oldEntity.setHouseIdcard(vo.getHouseIdcard());
        oldEntity.setHouseName(vo.getHouseName());
        oldEntity.setRelationshipType(vo.getRelationshipType());

        EduFormSpecialQueryVO queryVO = new EduFormSpecialQueryVO();
        queryVO.setYear(oldEntity.getYear());
        queryVO.setBigClassValue(oldEntity.getConfigTypeName());
        queryVO.setSmallClassValue(oldEntity.getConfigName());
        queryVO.setAreaCode(oldEntity.getAreaCode());

        EduFormSpecialVO eduFormSpecialVO = eduFormSpecialService.getBySmallValue(queryVO);
        if (eduFormSpecialVO != null) {
            if (BoolEnum.TRUE.getType().equalsIgnoreCase(eduFormSpecialVO.getHouseFlag())) {
                if (StringUtils.isBlank(vo.getHouseId())) {
                    throw new AppException("房产不能为空");
                }
            }
        }
        if (StringUtils.isNotBlank(vo.getHouseId())) {
            EduHouse eduHouse = eduHouseService.getHouseById(vo.getHouseId());
            if (eduHouse == null) {
                throw new AppException("系统中未找到房产信息");
            }
            oldEntity.setHouseAdreess(eduHouse.getAddress());
        }

        eduStudentEnrollBeforeService.updateById(oldEntity);
        eduEnrollClearCacheHelper.clearCachePreBefore(oldEntity.getStudentEnrollPreId());
        return vo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBeforeJh0005", title = "义务教育阶段预报名表特殊通道修改金华", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "eduStudentEnrollBeforeJh0005",
            operationName = "义务教育阶段预报名表特殊通道修改金华",
            dataType = "enrollBeforeId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public StudentEnrollBeforeSaveVO editJh(StudentEnrollBeforeSaveVO vo) {
        if (ObjectUtils.isEmpty(vo.getEnrollBeforeId())) {
            throw new AppException("传入需要修改的主键不能为空!");
        }

        if(StringUtils.isBlank(vo.getConfigTypeName())){
            throw new AppException("政策类别不能为空");
        }
        EduStudentEnrollBefore oldEntity = eduStudentEnrollBeforeService.getById(vo.getEnrollBeforeId());
        if (ObjectUtils.isEmpty(oldEntity)) {
            throw new AppException("查询不到需要修改的信息!");
        }
        EduSchoolVO eduSchool = eduSchoolService.getDetail(vo.getSchoolId());
        if (eduSchool == null) {
            throw new AppException("学校信息不存在");
        }
        eduStudentEnrollPreIntegration.edit(vo.getStudentEnrollPreVO());

        //保存数据
        if (StringUtils.isBlank(vo.getAuthStatus())) {
            vo.setAuthStatus(AuthStatusEnum.YES.getType());
            vo.setAuthRemarks("有权限的系统操作员修改");
        }
        oldEntity.setConfigTypeName(vo.getConfigTypeName());
        if(StringUtils.isBlank(vo.getConfigName())){
            LambdaQueryWrapper<EduFormSpecial> specialLambdaQueryWrapper=new LambdaQueryWrapper<>();
            specialLambdaQueryWrapper.eq(EduFormSpecial::getAreaCode,eduSchool.getAreaCode())
                    .eq(EduFormSpecial::getYear,vo.getYear())
                    .eq(EduFormSpecial::getBigClassValue,vo.getConfigTypeName());
            EduFormSpecial eduFormSpecial=eduFormSpecialService.getOne(specialLambdaQueryWrapper,false);
            if (eduFormSpecial!=null){
                oldEntity.setConfigName(eduFormSpecial.getSmallClassValue());
                oldEntity.setConfigNameAlias(eduFormSpecial.getSmallClassValue());
            }
        }

        oldEntity.setSchoolId(vo.getSchoolId());
        oldEntity.setHouseId(vo.getHouseId());
        oldEntity.setHouseIdcard(vo.getHouseIdcard());
        oldEntity.setHouseName(vo.getHouseName());
        oldEntity.setRelationshipType(vo.getRelationshipType());
        eduStudentEnrollBeforeService.updateById(oldEntity);
        eduEnrollClearCacheHelper.clearCachePreBefore(oldEntity.getStudentEnrollPreId());
        return vo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0006", title = "义务教育阶段预报名表根据主键删除", funcType = FuncTypeEnum.delete)
    @SaveOplog(
            operationType = "eduStudentEnrollBefore0006",
            operationName = "义务教育阶段预报名表删除",
            dataType = "enrollBeforeId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void del(EduStudentEnrollBeforeKeyVO vo) {
        if (ObjectUtils.isEmpty(vo.getEnrollBeforeId())) {
            throw new AppException("传入需要删除的数据主键不能为空!");
        }
        EduStudentEnrollBefore entity = eduStudentEnrollBeforeService.getById(vo.getEnrollBeforeId());
        if (ObjectUtils.isEmpty(entity)) {
            throw new AppException("未找到需要删除的信息!");
        }
        eduStudentEnrollBeforeService.removeById(vo.getEnrollBeforeId());
        eduEnrollClearCacheHelper.clearCachePreBefore(entity.getStudentEnrollPreId());
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0007", title = "查询特殊通道预报名数据", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollPreVO> querySpecialList(EduStudentEnrollPreQueryVO vo) {
        if (vo.getYear() == null) {
            throw new AppException("年度不能为空");
        }
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(20);
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());

        if (StringUtils.isBlank(vo.getSchoolId())) {
            String orgId=SessionUtil.getSessionInfo().getOrgId();
            if(eduSchoolService.getById(orgId)!=null){
                vo.setSchoolId(orgId);
            }else{
                if(StringUtils.isBlank(vo.getAreaCode())){
                    vo.setAreaCode(SessionUtil.getAreaCode());
                }
            }

        }
        vo.setSpecialFlag(BoolEnum.TRUE.getType());
        List<EduStudentEnrollPreVO> list = eduStudentEnrollBeforeService.queryPreList(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        PageInfo<EduStudentEnrollPreVO> pageInfo = new PageInfo<>(list);
        QueryWrapper<EduStudentEnrollBefore> beforeQueryWrapper = new QueryWrapper<>();
        beforeQueryWrapper.lambda()
                .eq(EduStudentEnrollBefore::getSpecialFlag, BoolEnum.TRUE.getType())
                .eq(EduStudentEnrollBefore::getSchoolId, vo.getSchoolId())
                .eq(EduStudentEnrollBefore::getYear, vo.getYear())
                .in(EduStudentEnrollBefore::getStudentEnrollPreId, list.stream().map(EduStudentEnrollPreVO::getStudentEnrollPreId)
                        .collect(Collectors.toList()));
        List<EduStudentEnrollBefore> beforeList = eduStudentEnrollBeforeService.list(beforeQueryWrapper);
        Map<String, EduStudentEnrollBefore> beforeMap = beforeList.stream().collect(
                Collectors.toMap(EduStudentEnrollBefore::getStudentEnrollPreId,
                        a -> a, (k1, k2) -> k1));
        for (EduStudentEnrollPreVO item : list) {
            EduStudentEnrollBefore before = beforeMap.get(item.getStudentEnrollPreId());
            if (before != null) {
                item.setEnrollBeforeId(before.getEnrollBeforeId());
                item.setConfigName(before.getConfigName());
                item.setConfigTypeName(before.getConfigTypeName());
            }
        }
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBeforeJh0007", title = "管理员查询特殊通道预报名数据", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollPreVO> querySpecialListManager(EduStudentEnrollPreQueryVO vo) {
        if (vo.getYear() == null) {
            throw new AppException("年度不能为空");
        }
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(20);
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<EduStudentEnrollPreVO> list=eduStudentEnrollBeforeService.queryPreListManager(vo);
        if(CollectionUtils.isEmpty(list)){
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        PageInfo<EduStudentEnrollPreVO> preVOPageInfo=new PageInfo<>(list);
        return preVOPageInfo;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0009", title = "特殊通道预报名数据单个查询", funcType = FuncTypeEnum.query)
    public StudentEnrollBeforeSaveVO getSpecialDetail(EduStudentEnrollBeforeQueryVO vo) {
        StudentEnrollBeforeSaveVO retVO = null;
        if (vo.getEnrollBeforeId() != null) {
            EduStudentEnrollBefore before = eduStudentEnrollBeforeService.getById(vo.getEnrollBeforeId());
            if (before == null) {
                throw new AppException("未找到特殊通道人员信息,请先新增");
            }

            EduStudentEnrollPre pre = eduStudentEnrollPreService.getById(before.getStudentEnrollPreId());
            if (pre == null) {
                throw new AppException("未找到特殊通道人员信息,请先新增");
            }
            retVO = Convert.convert(StudentEnrollBeforeSaveVO.class, pre);
            BeanUtil.copyProperties(before, retVO);
        } else if (StringUtils.isNotBlank(vo.getStudentEnrollPreId())) {
            EduStudentEnrollPre pre = eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
            if (pre == null) {
                throw new AppException("未找到特殊通道人员信息,请先新增");
            }
            retVO = Convert.convert(StudentEnrollBeforeSaveVO.class, pre);
            QueryWrapper<EduStudentEnrollBefore> beforeQueryWrapper = new QueryWrapper<>();
            beforeQueryWrapper.lambda().eq(EduStudentEnrollBefore::getStudentEnrollPreId, vo.getStudentEnrollPreId())
                    .eq(EduStudentEnrollBefore::getSchoolId, SessionUtil.getOrgId());
            List<EduStudentEnrollBefore> beforeList = eduStudentEnrollBeforeService.list(beforeQueryWrapper);
            if (!CollectionUtils.isEmpty(beforeList)) {
                BeanUtil.copyProperties(beforeList.get(0), retVO);
            }
        } else if (StringUtils.isNotBlank(vo.getIdcard())) {
            EduOperationCacheDetailVO eduOperationCacheDetailVO=operationCacheIntegration.getPeriodYear();
            Integer year=eduOperationCacheDetailVO.getYear();
            QueryWrapper<EduStudentEnrollPre> preQueryWrapper = new QueryWrapper<>();
            preQueryWrapper.lambda().eq(EduStudentEnrollPre::getYear, year)
                    .eq(EduStudentEnrollPre::getIdcard, vo.getIdcard());
            List<EduStudentEnrollPre> preList = eduStudentEnrollPreService.list(preQueryWrapper);
            if (!CollectionUtils.isEmpty(preList)) {
                EduStudentEnrollPre pre = preList.get(0);
                retVO = Convert.convert(StudentEnrollBeforeSaveVO.class, pre);
                QueryWrapper<EduStudentEnrollBefore> beforeQueryWrapper = new QueryWrapper<>();
                beforeQueryWrapper.lambda().eq(EduStudentEnrollBefore::getStudentEnrollPreId, pre.getStudentEnrollPreId())
                        .eq(EduStudentEnrollBefore::getSchoolId, SessionUtil.getOrgId())
                        .eq(EduStudentEnrollBefore::getSpecialFlag, BoolEnum.TRUE.getType());
                List<EduStudentEnrollBefore> beforeList = eduStudentEnrollBeforeService.list(beforeQueryWrapper);
                if (!CollectionUtils.isEmpty(beforeList)) {
                    BeanUtil.copyProperties(beforeList.get(0), retVO);
                }
            }
        }

        if(retVO!=null){
            if(StringUtils.isNotEmpty(retVO.getHouseId())){
                EduHouse eduHouse = eduHouseService.getById(retVO.getHouseId());
                if(eduHouse!=null){
                    List<EduHouseVO> houseVOList = new ArrayList<>();
                    houseVOList.add(Convert.convert(EduHouseVO.class,eduHouse));
                    retVO.setEduhouseList(houseVOList);
                }
            }
        }

        if (retVO != null && StringUtils.isNotBlank(retVO.getConfigTypeName()) && StringUtils.isNotBlank(retVO.getConfigName())) {
            List<String> configNameList = new ArrayList<>();
            configNameList.add(retVO.getConfigTypeName());
            configNameList.add(retVO.getConfigName());
            retVO.setConfigNameList(configNameList);
            EduFormSpecialQueryVO queryVO = new EduFormSpecialQueryVO();
            queryVO.setBigClassValue(retVO.getConfigTypeName());
            queryVO.setSmallClassValue(retVO.getConfigName());
            queryVO.setYear(eduHelper.thisYear());
            EduFormSpecialVO specialVO = eduFormSpecialService.getBySmallValue(queryVO);
            if(specialVO!=null) {
                retVO.setHouseFlag(specialVO.getHouseFlag());
                retVO.setHouseType(specialVO.getHouseType());
            }
        }
        return retVO;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0010", title = "预报名管理查询预采集数据列表", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollPreVO> queryPreList(EduStudentEnrollPreQueryVO vo) {
        return this.queryPagePreList(vo);
    }
    @Override
    public PageInfo<EduStudentEnrollPreVO> queryPagePreList(EduStudentEnrollPreQueryVO vo) {
        if (vo.getYear() == null) {
            throw new AppException("查询年度不能为空");
        }
        //由于处理数据比较多，必须开启分页，且每页最大不能超过200
        if (vo.getPageNum() == null) {
            vo.setPageNum(1);
        }
        if (vo.getPageSize() == null) {
            vo.setPageSize(100);
        }
        if (vo.getPageSize() > 200) {
            throw new AppException("由于执行性能原因，每页最大条数不能超过200");
        }
        List<String> areaCodeList = new ArrayList<>();
        if (ObjectUtils.isEmpty(vo.getAreaCode())){
            List<SelectVO> selectVOList = dictIntegration.getDistrictByOrg(new DictAreaVO());
            areaCodeList = selectVOList.stream()
                    .map(SelectVO::getDictKey)
                    .collect(Collectors.toList());
            String sessionAreaCode = SessionUtil.getAreaCode();
            if (!areaCodeList.contains(sessionAreaCode)) {
                areaCodeList.add(sessionAreaCode);
            }
        }else {
            areaCodeList.add(vo.getAreaCode());
        }
        if (!CollectionUtils.isEmpty(areaCodeList)){
            vo.setAreaCodeList(areaCodeList);
        }else{
            throw new AppException("必须传入行政区划");
        }
        //根据任务判断是否当前年度处理过迁移数据
        Boolean queryHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),handleTable);
        List<EduStudentEnrollPreVO> list;
        if (!queryHistoryFlag) {
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            list = eduStudentEnrollBeforeService.queryPreList(vo);
        }else {
            // 迁移过后，判断是否加密
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), handleTable));
            //如果加密，把查询条件加密
            if (encryptFlag) {
                //加密查询条件
                if (StringUtils.isNotBlank(vo.getIdcard())){
                    vo.setIdcard(CommonSecureUtil.sm4Encrypt(vo.getIdcard()));
                }
                if (StringUtils.isNotBlank(vo.getFullName())){
                    vo.setFullName(CommonSecureUtil.sm4Encrypt(vo.getFullName()));
                }
                if (StringUtils.isNotBlank(vo.getFatherName())){
                    vo.setFatherName(CommonSecureUtil.sm4Encrypt(vo.getFatherName()));
                }
                if (StringUtils.isNotBlank(vo.getFatherIdcard())){
                    vo.setFatherIdcard(CommonSecureUtil.sm4Encrypt(vo.getFatherIdcard()));
                }
                if (StringUtils.isNotBlank(vo.getFatherCellphone())){
                    vo.setFatherCellphone(CommonSecureUtil.sm4Encrypt(vo.getFatherCellphone()));
                }
                if (StringUtils.isNotBlank(vo.getMotherName())){
                    vo.setMotherName(CommonSecureUtil.sm4Encrypt(vo.getMotherName()));
                }
                if (StringUtils.isNotBlank(vo.getMotherIdcard())){
                    vo.setMotherIdcard(CommonSecureUtil.sm4Encrypt(vo.getMotherIdcard()));
                }
                if (StringUtils.isNotBlank(vo.getMotherCellphone())){
                    vo.setMotherCellphone(CommonSecureUtil.sm4Encrypt(vo.getMotherCellphone()));
                }
            }
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            list = eduStudentEnrollBeforeService.queryPreListHistory(vo);
        }
        if (CollectionUtils.isEmpty(list)) {
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        PageInfo<EduStudentEnrollPreVO> pageInfo = new PageInfo<>(list);
        List<EduStudentEnrollPreVO> retList = pageInfo.getList();
        List<String> idcardList = new ArrayList<>();//学生身份证
        List<String> preIdList = new ArrayList<>();//预采集id
        List<String> cjSchoolIdList = new ArrayList<>();//采集学校
        for (EduStudentEnrollPreVO preVO : retList) {
            if ("1".equals(preVO.getEncryptFlag())){
                if (StringUtils.isNotBlank(preVO.getIdcard())){
                    preVO.setIdcard(CommonSecureUtil.sm4Decrypt(preVO.getIdcard()));
                }
                if (StringUtils.isNotBlank(preVO.getFullName())){
                    preVO.setFullName(CommonSecureUtil.sm4Decrypt(preVO.getFullName()));
                }
                if (StringUtils.isNotBlank(preVO.getFatherName())){
                    preVO.setFatherName(CommonSecureUtil.sm4Decrypt(preVO.getFatherName()));
                }
                if (StringUtils.isNotBlank(preVO.getFatherIdcard())){
                    preVO.setFatherIdcard(CommonSecureUtil.sm4Decrypt(preVO.getFatherIdcard()));
                }
                if (StringUtils.isNotBlank(preVO.getFatherCellphone())){
                    preVO.setFatherCellphone(CommonSecureUtil.sm4Decrypt(preVO.getFatherCellphone()));
                }
                if (StringUtils.isNotBlank(preVO.getMotherName())){
                    preVO.setMotherName(CommonSecureUtil.sm4Decrypt(preVO.getMotherName()));
                }
                if (StringUtils.isNotBlank(preVO.getMotherIdcard())){
                    preVO.setMotherIdcard(CommonSecureUtil.sm4Decrypt(preVO.getMotherIdcard()));
                }
                if (StringUtils.isNotBlank(preVO.getMotherCellphone())){
                    preVO.setMotherCellphone(CommonSecureUtil.sm4Decrypt(preVO.getMotherCellphone()));
                }
            }
            preIdList.add(preVO.getStudentEnrollPreId());
            List<String> allIdcardList = new ArrayList<>();//学生身份证+父母身份证
            if (StringUtils.isNotBlank(preVO.getIdcard())) {
                idcardList.add(preVO.getIdcard());
                allIdcardList.add(preVO.getIdcard());
            }
            if (StringUtils.isNotBlank(preVO.getFatherIdcard())) {
                allIdcardList.add(preVO.getFatherIdcard());
            }
            if (StringUtils.isNotBlank(preVO.getMotherIdcard())) {
                allIdcardList.add(preVO.getMotherIdcard());
            }
            if (!CollectionUtils.isEmpty(allIdcardList)) {
                //根据房产任务判断是否当前年度处理过迁移数据
                Boolean houseHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),handleTableHouse);
                //根据身份证获取房产信息
                if (!houseHistoryFlag) {
                    List<EduHouse> houseList = eduHouseService.getHouseByAllIdcard(allIdcardList, preVO.getYear());
                    if (!CollectionUtils.isEmpty(houseList)) {
                        preVO.setHouseList(Convert.toList(EduHouseVO.class, houseList));
                        preVO.setHouseAddress(houseList.stream().map(EduHouse::getAddress).distinct().collect(Collectors.joining(",")));
                    }
                }else {
                    // 迁移过后，判断是否加密
                    Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), handleTableHouseDetail));
                    List<EduhHouse> houseListHistory;
                    if (encryptFlag) {
                        ArrayList<String> allIdcardListEncrypts = new ArrayList<>();
                        //加密查询条件
                        for (String idCard : allIdcardList) {
                            allIdcardListEncrypts.add(CommonSecureUtil.sm4Encrypt(idCard));
                        }
                        houseListHistory = eduHouseService.getHouseByAllIdcardHistory(allIdcardListEncrypts, preVO.getYear());
                    } else {
                        //没有加密就用原始的身份证查询
                        houseListHistory = eduHouseService.getHouseByAllIdcardHistory(allIdcardList, preVO.getYear());
                    }
                    if (!CollectionUtils.isEmpty(houseListHistory)) {
                        //解密
                        for (EduhHouse eduhHouse : houseListHistory) {
                            if ("1".equals(eduhHouse.getEncryptFlag())){
                                if (StringUtils.isNotBlank(eduhHouse.getAddress())) {
                                    eduhHouse.setAddress(CommonSecureUtil.sm4Decrypt(eduhHouse.getAddress()));
                                }
                                if (StringUtils.isNotBlank(eduhHouse.getQlrName())) {
                                    eduhHouse.setQlrName(CommonSecureUtil.sm4Decrypt(eduhHouse.getQlrName()));
                                }
                            }
                        }
                        preVO.setHouseList(Convert.toList(EduHouseVO.class, houseListHistory));
                        preVO.setHouseAddress(houseListHistory.stream().map(EduhHouse::getAddress).distinct().collect(Collectors.joining(",")));
                    }
                }

            }
            if (StringUtils.isNotBlank(preVO.getOrgId())) {
                cjSchoolIdList.add(preVO.getOrgId());
            }
        }
        //获取采集学校
        Map<String, String> cjSchoolMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(cjSchoolIdList)) {
            List<EduSchool> schoolList = eduSchoolService.listByIds(cjSchoolIdList);
            if (!CollectionUtils.isEmpty(schoolList)) {
                cjSchoolMap = schoolList.stream().collect(Collectors.toMap(EduSchool::getOrgId, EduSchool::getSchoolName, (k1, k2) -> k1));
            }
        }
        Map<String, List<EduHousehold>> householdMap = new HashMap<>();
        Map<String, String> appointStudentMap = new HashMap<>();
        Map<String, String> privateAppointStudentMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(idcardList)) {
            //根据任务判断是否当前年度处理过迁移数据
            Boolean householdHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),handleTablehousehold);
            if (!householdHistoryFlag) {
                //根据身份证获取户籍信息
                QueryWrapper<EduHousehold> queryWrapper = new QueryWrapper<>();
                queryWrapper.lambda().in(EduHousehold::getIdcard, idcardList)
                        .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                        .eq(EduHousehold::getYear, vo.getYear())
                        .orderByDesc(EduHousehold::getQysj);
                List<EduHousehold> householdList = eduHouseholdService.list(queryWrapper);
                if (!CollectionUtils.isEmpty(householdList)) {
                    householdMap = householdList.stream().collect(Collectors.groupingBy(EduHousehold::getIdcard));
                }
            }else {
                //根据身份证获取户籍信息
                QueryWrapper<EduhHousehold> queryWrapper = new QueryWrapper<>();
                queryWrapper.lambda()
                        .eq(EduhHousehold::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduhHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                        .eq(EduhHousehold::getYear, vo.getYear())
                        .orderByDesc(EduhHousehold::getQysj);
                // 迁移过后，判断是否加密
                Boolean householdEncryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), handleTablehousehold));
                if (householdEncryptFlag) {
                    ArrayList<String> idcardListEncrypt = new ArrayList<>();
                    //加密查询条件
                    for (String idCard  : idcardList) {
                        idcardListEncrypt.add(CommonSecureUtil.sm4Encrypt(idCard));
                    }
                    //加密了就用加密后的身份证
                    queryWrapper.lambda().in(EduhHousehold::getIdcard, idcardListEncrypt);
                }else {
                    //没有加密就用原始的身份证
                    queryWrapper.lambda().in(EduhHousehold::getIdcard, idcardList);
                }
                List<EduhHousehold> eduhHouseholdList = eduhHouseholdService.list(queryWrapper);
                if (!CollectionUtils.isEmpty(eduhHouseholdList)) {
                    //判断是否需要解密
                    for (EduhHousehold eduhHousehold : eduhHouseholdList) {
                        if ("1".equals(eduhHousehold.getEncryptFlag())) {
                            if (StringUtils.isNotBlank(eduhHousehold.getIdcard())){
                                eduhHousehold.setIdcard(CommonSecureUtil.sm4Decrypt(eduhHousehold.getIdcard()));
                            }
                            if (StringUtils.isNotBlank(eduhHousehold.getFullName())){
                                eduhHousehold.setFullName(CommonSecureUtil.sm4Decrypt(eduhHousehold.getFullName()));
                            }
                            if (StringUtils.isNotBlank(eduhHousehold.getBeforeName())){
                                eduhHousehold.setBeforeName(CommonSecureUtil.sm4Decrypt(eduhHousehold.getBeforeName()));
                            }
                            if (StringUtils.isNotBlank(eduhHousehold.getAddress())){
                                eduhHousehold.setAddress(CommonSecureUtil.sm4Decrypt(eduhHousehold.getAddress()));
                            }
                            if (StringUtils.isNotBlank(eduhHousehold.getHouseholdPlace())){
                                eduhHousehold.setHouseholdPlace(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholdPlace()));
                            }
                            if (StringUtils.isNotBlank(eduhHousehold.getHouseholder())){
                                eduhHousehold.setHouseholder(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholder()));
                            }
                            if (StringUtils.isNotBlank(eduhHousehold.getHouseholderIdcard())){
                                eduhHousehold.setHouseholderIdcard(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholderIdcard()));
                            }
                        }
                    }
                    List<EduHousehold> eduHouseholds = Convert.toList(EduHousehold.class, eduhHouseholdList);
                    householdMap = eduHouseholds.stream().collect(Collectors.groupingBy(EduHousehold::getIdcard));
                }
            }

            //获取城区E
            QueryWrapper<EduAppointStudent> appointStudentQueryWrapper = new QueryWrapper<>();
            appointStudentQueryWrapper.lambda().eq(EduAppointStudent::getStatus, AuthStatusEnum.YES.getType())
                    .eq(EduAppointStudent::getYear, vo.getYear())
                    .in(EduAppointStudent::getIdcard, idcardList);
            List<EduAppointStudent> appointStudentList = eduAppointStudentService.list(appointStudentQueryWrapper);
            if (!CollectionUtils.isEmpty(appointStudentList)) {
                appointStudentMap = appointStudentList.stream().collect(Collectors.toMap(EduAppointStudent::getIdcard, EduAppointStudent::getSchoolId, (k1, k2) -> k1));
            }
            //获取直升班信息
            QueryWrapper<EduPrivateAppointStudent> privateAppointStudentQueryWrapper = new QueryWrapper<>();
            privateAppointStudentQueryWrapper.lambda().eq(EduPrivateAppointStudent::getStatus, AuthStatusEnum.YES.getType())
                    .eq(EduPrivateAppointStudent::getYear, vo.getYear())
                    .in(EduPrivateAppointStudent::getIdcard, idcardList);
            List<EduPrivateAppointStudent> privateAppointStudentList = eduPrivateAppointStudentService.list(privateAppointStudentQueryWrapper);

            if (!CollectionUtils.isEmpty(privateAppointStudentList)) {
                privateAppointStudentMap = privateAppointStudentList.stream().collect(Collectors.toMap(EduPrivateAppointStudent::getIdcard, EduPrivateAppointStudent::getSchoolId, (k1, k2) -> k1));
            }
        }
        Map<String, List<EduStudentEnrollBeforeVO>> beforeMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(preIdList)) {
            //获取可就读学校信息
            EduStudentEnrollBeforeQueryVO queryVO = new EduStudentEnrollBeforeQueryVO();
            queryVO.setStudentEnrollPreIdList(preIdList);
            queryVO.setYear(vo.getYear());
            //去原始表没有查到数据就去历史表看看有没有
            List<EduStudentEnrollBeforeVO> beforeVOList = eduStudentEnrollBeforeService.queryBeforeList(queryVO);
            if (CollectionUtils.isEmpty(beforeVOList)){
                beforeVOList = eduStudentEnrollBeforeService.queryBeforeListHistory(queryVO);
            }
            if (!CollectionUtils.isEmpty(beforeVOList)) {
                beforeMap = beforeVOList.stream().collect(Collectors.groupingBy(EduStudentEnrollBeforeVO::getStudentEnrollPreId));
            }
        }
        //获取报名情况
        List<String> enrollStatusList = new ArrayList<>();
        enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
        // 判断是否查询历史表
        Map<String, String> enrollMap = new HashMap<>();
        Boolean enrollQueryHistoryFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), handleTableenroll));
        if (!enrollQueryHistoryFlag) {
            QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
            enrollQueryWrapper.lambda().select(EduStudentEnroll::getIdcard, EduStudentEnroll::getEnrollStatus).in(EduStudentEnroll::getIdcard, idcardList)
                    .eq(EduStudentEnroll::getYear, vo.getYear())
                    .in(EduStudentEnroll::getEnrollStatus, enrollStatusList)
                    .orderByAsc(EduStudentEnroll::getCreateTime);
            List<EduStudentEnroll> eduStudentEnrollList = eduStudentEnrollService.list(enrollQueryWrapper);
            if (!CollectionUtils.isEmpty(eduStudentEnrollList)) {
                enrollMap = eduStudentEnrollList.stream().collect(Collectors.toMap(EduStudentEnroll::getIdcard, EduStudentEnroll::getEnrollStatus, (k1, k2) -> k1));
            }
        }else{
            QueryWrapper<EduhStudentEnroll> eduhEnrollQueryWrapper = new QueryWrapper<>();
            eduhEnrollQueryWrapper.lambda().select(EduhStudentEnroll::getIdcard, EduhStudentEnroll::getEnrollStatus)
                    .eq(EduhStudentEnroll::getYear, vo.getYear())
                    .in(EduhStudentEnroll::getEnrollStatus, enrollStatusList)
                    .orderByAsc(EduhStudentEnroll::getCreateTime);
            // 迁移过后，判断是否加密
            Boolean enrollEncryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), handleTableenroll));
            if (enrollEncryptFlag) {
                ArrayList<String> idcardListEncrypt = new ArrayList<>();
                //加密查询条件
                for (String idCard  : idcardList) {
                    idcardListEncrypt.add(CommonSecureUtil.sm4Encrypt(idCard));
                }
                //加密了就用加密后的身份证
                eduhEnrollQueryWrapper.lambda().in(EduhStudentEnroll::getIdcard, idcardListEncrypt);
            }else {
                //没有加密就用原始的身份证
                eduhEnrollQueryWrapper.lambda().in(EduhStudentEnroll::getIdcard, idcardList);
            }

            List<EduhStudentEnroll> eduhStudentEnrollList = eduhStudentEnrollService.list(eduhEnrollQueryWrapper);
            if (!CollectionUtils.isEmpty(eduhStudentEnrollList)) {
                //判断是否需要解密
                List<EduStudentEnrollVO> eduStudentEnrollVOList = Convert.toList(EduStudentEnrollVO.class, eduhStudentEnrollList);
                for (EduStudentEnrollVO eduStudentEnrollVO : eduStudentEnrollVOList) {
                    if ("1".equals(eduStudentEnrollVO.getEncryptFlag())) {
                        eduStudentEnrollService.decrypt(eduStudentEnrollVO);
                    }
                }
                enrollMap = eduStudentEnrollVOList.stream().collect(Collectors.toMap(EduStudentEnrollVO::getIdcard, EduStudentEnrollVO::getEnrollStatus, (k1, k2) -> k1));
            }
        }

        for (EduStudentEnrollPreVO preVO : retList) {
            if (enrollMap.containsKey(preVO.getIdcard())) {
                preVO.setBmFlag(true);
                preVO.setEnrollStatus(enrollMap.get(preVO.getIdcard()));
            } else {
                preVO.setBmFlag(false);
            }
            preVO.setCjSchoolName(cjSchoolMap.get(preVO.getOrgId()));
            List<EduHousehold> householdList = householdMap.get(preVO.getIdcard());
            if (!CollectionUtils.isEmpty(householdList)) {
                EduHouseholdVO household = Convert.convert(EduHouseholdVO.class, householdList.get(0));
                preVO.setHouseHoldVO(household);
                preVO.setHouseholdAddress(household.getAddress());
            }
            List<EduStudentEnrollBeforeVO> studentEnrollBeforeVOList = beforeMap.get(preVO.getStudentEnrollPreId());
            if (!CollectionUtils.isEmpty(studentEnrollBeforeVOList)) {
                String school = "";
                int i = 1;
                for (EduStudentEnrollBeforeVO studentEnrollBeforeVO : studentEnrollBeforeVOList) {
                    if (i > 1) {
                        school = school + ",";
                    }
                    String configName=BoolEnum.TRUE.getType().equals(studentEnrollBeforeVO.getSpecialFlag())?"特殊通道":studentEnrollBeforeVO.getConfigName();
                    String configNameAlias=studentEnrollBeforeVO.getConfigNameAlias();
                    school = school + studentEnrollBeforeVO.getShortName() + "(" + configName+(StringUtils.isNotBlank(configNameAlias)?"-"+configNameAlias:"") + ")";
                    i++;
                }
                preVO.setEnrollBeforeList(studentEnrollBeforeVOList);
                preVO.setSchool(school);
            }
            if (appointStudentMap.containsKey(preVO.getIdcard())) {
                preVO.setAppointFlag(BoolEnum.TRUE.getType());
            } else {
                preVO.setAppointFlag(BoolEnum.FALSE.getType());
            }
            if (privateAppointStudentMap.containsKey(preVO.getIdcard())) {
                preVO.setPrivateAppointFlag(BoolEnum.TRUE.getType());
            } else {
                preVO.setPrivateAppointFlag(BoolEnum.FALSE.getType());
            }
            preVO.setSchoolCategoryName(dictHelper.getValue("schoolCategory", preVO.getSchoolCategory()));
            if (StringUtils.isBlank(preVO.getFatherCardType())) {
                preVO.setFatherCardType(CardTypeEnum.idcard.getType());
            }
            if (StringUtils.isBlank(preVO.getMotherCardType())) {
                preVO.setMotherCardType(CardTypeEnum.idcard.getType());
            }
        }
        return PagerUtil.parsePagerVo(retList, pageInfo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0016", title = "预报名管理查询预报名列表", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollBeforeVO> queryBeforeList(EduStudentEnrollBeforeQueryVO studentEnrollBeforeQueryVO) {
        return this.queryBeforePageList(studentEnrollBeforeQueryVO);
    }

    @Override
    public PageInfo<EduStudentEnrollBeforeVO> queryBeforePageList(EduStudentEnrollBeforeQueryVO studentEnrollBeforeQueryVO) {
        if(studentEnrollBeforeQueryVO.getYear()==null){
            throw new AppException("查询年度不能为空");
        }
        // 开启分页
        if (studentEnrollBeforeQueryVO.getPageNum() == null || studentEnrollBeforeQueryVO.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            studentEnrollBeforeQueryVO.setPageNum(1);
            studentEnrollBeforeQueryVO.setPageSize(50);
        }
        //判断预采集表是否迁移
        List<EduStudentEnrollBeforeVO> list;
        Boolean queryHistoryFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyQueryHistory(studentEnrollBeforeQueryVO.getYear(), STUDENT_ENROLL_PRE));
        if (!queryHistoryFlag) {
            PageHelper.startPage(studentEnrollBeforeQueryVO.getPageNum(), studentEnrollBeforeQueryVO.getPageSize());
            list = eduStudentEnrollBeforeService.queryBeforeList(studentEnrollBeforeQueryVO);
            if (CollectionUtils.isEmpty(list)) {
                return PagerUtil.createEmptyPagerInfo(studentEnrollBeforeQueryVO.getPageNum(), studentEnrollBeforeQueryVO.getPageSize());
            }
        }else {
            // 迁移过后，判断是否加密
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(studentEnrollBeforeQueryVO.getYear(), STUDENT_ENROLL_PRE));
            if (encryptFlag) {
                //加密查询条件
                if (StringUtils.isNotBlank(studentEnrollBeforeQueryVO.getIdcard())){
                    studentEnrollBeforeQueryVO.setIdcard(CommonSecureUtil.sm4Encrypt(studentEnrollBeforeQueryVO.getIdcard()));
                }
                if (StringUtils.isNotBlank(studentEnrollBeforeQueryVO.getAllIdcard())){
                    studentEnrollBeforeQueryVO.setAllIdcard(CommonSecureUtil.sm4Encrypt(studentEnrollBeforeQueryVO.getAllIdcard()));
                }
            }
            PageHelper.startPage(studentEnrollBeforeQueryVO.getPageNum(), studentEnrollBeforeQueryVO.getPageSize());
            list = eduStudentEnrollBeforeService.queryBeforeListHistory(studentEnrollBeforeQueryVO);
            if (CollectionUtils.isEmpty(list)) {
                return PagerUtil.createEmptyPagerInfo(studentEnrollBeforeQueryVO.getPageNum(), studentEnrollBeforeQueryVO.getPageSize());
            }
            //解密
            for (EduStudentEnrollBeforeVO eduStudentEnrollBeforeVO : list) {
                if ("1".equals(eduStudentEnrollBeforeVO.getEncryptFlag())){
                    if (StringUtils.isNotBlank(eduStudentEnrollBeforeVO.getIdcard())){
                        eduStudentEnrollBeforeVO.setIdcard(CommonSecureUtil.sm4Decrypt(eduStudentEnrollBeforeVO.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduStudentEnrollBeforeVO.getFullName())){
                        eduStudentEnrollBeforeVO.setFullName(CommonSecureUtil.sm4Decrypt(eduStudentEnrollBeforeVO.getFullName()));
                    }
                }
            }
        }
        PageInfo<EduStudentEnrollBeforeVO> pageInfo = new PageInfo<>(list);
        Integer year= studentEnrollBeforeQueryVO.getYear();
        long curTime = DateUtil.currentSeconds();
        String enrollStatus = EnrollStatusEnum.wait.getType();
        String enrollStatusName = EnrollStatusEnum.wait.getName();
        Map<String, Long> brochureMap = new HashMap<>();
        if ("enroll".equals(studentEnrollBeforeQueryVO.getSearchType())) {
            EduOperationCacheQueryVO queryVO=new EduOperationCacheQueryVO();
            //判断义务段还是学前段
            String classify="2";
            queryVO.setClassify(classify);
            if(StringUtils.isBlank(studentEnrollBeforeQueryVO.getAreaCode())){
                queryVO.setAreaCode(eduHelper.thisAreaCode());
            }else {
                queryVO.setAreaCode(studentEnrollBeforeQueryVO.getAreaCode());
            }
            EduOperationCacheVO eduOperationCacheVO=eduSystemConfigIntegration.getEduOperation(queryVO);
            if(eduOperationCacheVO.getYear()>studentEnrollBeforeQueryVO.getYear()){
                enrollStatus=EnrollStatusEnum.finish.getType();
                enrollStatusName = EnrollStatusEnum.finish.getName();
            }else if(eduOperationCacheVO.getYear()-studentEnrollBeforeQueryVO.getYear()==0){
                Map<String, EduOperationCacheDetailVO> operation=eduOperationCacheVO.getOperation();
                EduOperationCacheDetailVO bmOp=operation.get("YW002");
                if(bmOp!=null&&bmOp.getBegTime()!=null&&bmOp.getEndTime()!=null){
                    long applyStart = bmOp.getBegTime().getTime() / 1000;
                    long applyEnd = bmOp.getEndTime().getTime() / 1000;
                    if (curTime >= applyStart && curTime <= applyEnd) {
                        enrollStatus = EnrollStatusEnum.on.getType();
                        enrollStatusName = EnrollStatusEnum.on.getName();
                    }else if (curTime > applyEnd) {
                        enrollStatus = EnrollStatusEnum.auth.getType();
                        enrollStatusName = EnrollStatusEnum.auth.getName();
                        //判断补报
                        EduOperationCacheDetailVO bBOp=operation.get("YW022");
                        if (bBOp!=null&&bBOp.getBegTime() != null && bBOp.getBegTime() != null) {
                            long applyStartTwo = bBOp.getBegTime().getTime() / 1000;
                            long applyEndTwo = bBOp.getEndTime().getTime() / 1000;
                            if (curTime >= applyStartTwo && curTime <= applyEndTwo) {
                                enrollStatus = EnrollStatusEnum.on.getType();
                                enrollStatusName = EnrollStatusEnum.on.getName();
                            } else if (curTime > applyEndTwo) {
                                //判断空额抢报
                                EduOperationCacheDetailVO qBOp=operation.get("YW010");
                                if (qBOp!=null&&qBOp.getBegTime() != null && qBOp.getEndTime() != null) {
                                    long spaceStart = qBOp.getBegTime().getTime() / 1000;
                                    long spaceEnd = qBOp.getEndTime().getTime() / 1000;
                                    if (curTime >= spaceStart && curTime <= spaceEnd) {
                                        enrollStatus = EnrollStatusEnum.onVacancy.getType();
                                        enrollStatusName = EnrollStatusEnum.onVacancy.getName();
                                    } else if (spaceEnd > applyEnd) {
                                        enrollStatus = EnrollStatusEnum.finish.getType();
                                        enrollStatusName = EnrollStatusEnum.finish.getName();
                                    }
                                }
                            }
                        }
                    }

                }
                //获取学校招生方案
                List<String> orgIdList =
                        list.stream().map(EduStudentEnrollBeforeVO::getSchoolId).distinct().collect(Collectors.toList());
                QueryWrapper<EduEnrollmenBrochure> brochureQueryWrapper = new QueryWrapper<>();
                brochureQueryWrapper.lambda().in(EduEnrollmenBrochure::getSchoolId, orgIdList)
                        .eq(EduEnrollmenBrochure::getYear, year);
                List<EduEnrollmenBrochure> brochureList =
                        eduEnrollmenBrochureService.list(brochureQueryWrapper);
                if (!CollectionUtils.isEmpty(brochureList)) {
                    brochureMap = brochureList.stream().collect(Collectors.toMap(EduEnrollmenBrochure::getSchoolId, EduEnrollmenBrochure::getArticleId, (k1, k2) -> k1));
                }
            }


        }
        final String enrollStatusFinal = enrollStatus;
        final String enrollStatusNameFinal = enrollStatusName;

        List<EduStudentEnrollBeforeVO> pageList = pageInfo.getList();
        //转义数据字典值
        dictHelper.valueToName(pageList, Arrays.asList(SchoolDictEnum.values()));
        Map<String, EduArea> areaMap =
                eduAreaService.list().stream()
                        .collect(Collectors.toMap(EduArea::getLocalCode, a -> a, (k1, k2) -> k1));
        // 获取学校空额名单
        Map<String, Integer> vacancyMap = new HashMap<>();
        if ("enroll".equals(studentEnrollBeforeQueryVO.getSearchType())) {
            List<String> schoolIdList = pageList.stream().map(EduStudentEnrollBeforeVO::getSchoolId).collect(Collectors.toList());
            QueryWrapper<EduSchoolVacancy> vacancyQueryWrapper = new QueryWrapper<>();
            vacancyQueryWrapper.lambda().select(EduSchoolVacancy::getSchoolId, EduSchoolVacancy::getVacancyNum)
                    .in(EduSchoolVacancy::getSchoolId, schoolIdList)
                    .eq(EduSchoolVacancy::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduSchoolVacancy::getYear, year);
            List<EduSchoolVacancy> vacancyList = eduSchoolVacancyService.list(vacancyQueryWrapper);

            if (!CollectionUtils.isEmpty(vacancyList)) {
                vacancyMap = vacancyList.stream().collect(Collectors.toMap(EduSchoolVacancy::getSchoolId, EduSchoolVacancy::getVacancyNum, (k1, k2) -> k1));
            }
        }
        //获取户籍信息
        List<String> houseIdList = new ArrayList<>();
        //获取房产信息
        List<String> householdIdList = new ArrayList<>();
        for (EduStudentEnrollBeforeVO studentEnrollBeforeVO : pageList) {
            if (StringUtils.isNotBlank(studentEnrollBeforeVO.getHouseId())) {
                if (!houseIdList.contains(studentEnrollBeforeVO.getHouseId())) {
                    houseIdList.add(studentEnrollBeforeVO.getHouseId());
                }
            }
            if (StringUtils.isNotBlank(studentEnrollBeforeVO.getHouseholdId())) {
                if (!householdIdList.contains(studentEnrollBeforeVO.getHouseholdId())) {
                    householdIdList.add(studentEnrollBeforeVO.getHouseholdId());
                }
            }
        }
        Map<String, EduHouse> houseMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(houseIdList)) {
            List<EduHouse> houseList;
            //查询房产历史表
            Boolean houseHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(studentEnrollBeforeQueryVO.getYear(), HOUSE_TABLE);
            if (!houseHistoryFlag) {
                QueryWrapper<EduHouse> houseQueryWrapper = new QueryWrapper<>();
                houseQueryWrapper.lambda().eq(EduHouse::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduHouse::getAuthStatus, AuthStatusEnum.YES.getType())
                        .in(EduHouse::getHouseId, houseIdList);
                houseList = eduHouseService.list(houseQueryWrapper);
            } else {
                QueryWrapper<EduhHouse> eduhHouseQueryWrapper = new QueryWrapper<>();
                eduhHouseQueryWrapper.lambda().eq(EduhHouse::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduhHouse::getAuthStatus, AuthStatusEnum.YES.getType())
                        .in(EduhHouse::getHouseId, houseIdList);
                List<EduhHouse> eduhHouseList = eduhHouseService.list(eduhHouseQueryWrapper);
                houseList = Convert.toList(EduHouse.class, eduhHouseList);
            }
            if (!CollectionUtils.isEmpty(houseList)) {
                houseMap = houseList.stream().collect(Collectors.toMap(EduHouse::getHouseId, a -> a, (k1, k2) -> k1));
            }
        }

        Map<String, EduHousehold> householdMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(householdIdList)) {
            //查询户籍历史表
            List<EduHousehold> householdList;
            Boolean houseHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(studentEnrollBeforeQueryVO.getYear(), HOUSEHOLD_TABLE);
            if (!houseHistoryFlag) {
                QueryWrapper<EduHousehold> houseQueryWrapper = new QueryWrapper<>();
                houseQueryWrapper.lambda().eq(EduHousehold::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                        .in(EduHousehold::getHouseholdId, householdIdList);
                householdList = eduHouseholdService.list(houseQueryWrapper);
            }else {
                QueryWrapper<EduhHousehold> eduhHouseQueryWrapper = new QueryWrapper<>();
                eduhHouseQueryWrapper.lambda().eq(EduhHousehold::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduhHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                        .in(EduhHousehold::getHouseholdId, householdIdList);
                List<EduhHousehold> eduhHouseholdList = eduhHouseholdService.list(eduhHouseQueryWrapper);
                householdList = Convert.toList(EduHousehold.class,eduhHouseholdList);
            }
            if (!CollectionUtils.isEmpty(householdList)) {
                householdMap = householdList.stream().collect(Collectors.toMap(EduHousehold::getHouseholdId, a -> a, (k1, k2) -> k1));
            }
        }
        final Map<String, EduHouse> houseMapFinal = houseMap;
        final Map<String, EduHousehold> householdMapFinal = householdMap;
        final Map<String, Integer> vacancyMapFinal = vacancyMap;
        final Map<String, Long> brochureMapFinal = brochureMap;
        pageList.forEach(
                item -> {
                    //设置街道
                    if (!ObjectUtils.isEmpty(areaMap.get(item.getStreet()))) {
                        item.setStreetName(areaMap.get(item.getStreet()).getAreaName());
                    }
                    if (StringUtils.isNotBlank(item.getHouseId())) {
                        EduHouse eduHouse = houseMapFinal.get(item.getHouseId());
                        if (eduHouse != null) {
                            item.setRealPropertyDetails(eduHouse.getRealProperty());
                            item.setRegisterDate(eduHouse.getRegisterDate());
                        }
                    }
                    if (StringUtils.isNotBlank(item.getHouseholdId())) {
                        EduHousehold eduHousehold = householdMapFinal.get(item.getHouseholdId());
                        if (eduHousehold != null) {
                            if (StringUtils.isNotBlank(eduHousehold.getQysj())) {
                                try {
                                    item.setQysj(DateUtil.parse(eduHousehold.getQysj(), DatePattern.PURE_DATETIME_FORMAT));
                                } catch (Exception e) {
                                    try {
                                        item.setQysj(DateUtil.parse(eduHousehold.getQysj().substring(0, 8), DatePattern.PURE_DATE_FORMAT));
                                    } catch (Exception ex) {
                                        log.error("户籍启用时间转换异常");
                                    }
                                }

                            }
                            item.setAddressCity(eduHousehold.getAddressCity());
                            item.setAddressCountry(eduHousehold.getAddressCountry());
                            item.setAddressVillage(eduHousehold.getAddressVillage());
                        }
                    }

                    if ("enroll".equals(studentEnrollBeforeQueryVO.getSearchType())) {
                        //设置学校报名状态
                        if (item.getYear() > year) {
                            item.setEnrollStatus(EnrollStatusEnum.wait.getType());
                            item.setEnrollStatusName(EnrollStatusEnum.wait.getName());
                        } else if (item.getYear() < year) {
                            item.setEnrollStatus(EnrollStatusEnum.finish.getType());
                            item.setEnrollStatusName(EnrollStatusEnum.finish.getName());
                        } else {
                            if (EnrollStatusEnum.onVacancy.getType().equals(enrollStatusFinal)) {
                                Integer num = vacancyMapFinal.get(item.getSchoolId());
                                if (num == null) {
                                    item.setEnrollStatus(EnrollStatusEnum.finish.getType());
                                    item.setEnrollStatusName(EnrollStatusEnum.finish.getName());
                                } else {
                                    if (num > 0) {
                                        item.setEnrollStatus(enrollStatusFinal);
                                        item.setEnrollStatusName(enrollStatusNameFinal);
                                        item.setVacancyNum(num);
                                    } else {
                                        item.setEnrollStatus(EnrollStatusEnum.finish.getType());
                                        item.setEnrollStatusName(EnrollStatusEnum.finish.getName());
                                    }
                                }
                            } else {
                                if (brochureMapFinal.containsKey(item.getSchoolId())) {
                                    item.setEnrollStatus(enrollStatusFinal);
                                    item.setEnrollStatusName(enrollStatusNameFinal);
                                } else {
                                    item.setEnrollStatus(EnrollStatusEnum.no.getType());
                                    item.setEnrollStatusName(EnrollStatusEnum.no.getName());
                                }

                            }
                        }
                    }
                });
        return PagerUtil.parsePagerVo(pageList, pageInfo);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0008", title = "预报名管理查询详情", funcType = FuncTypeEnum.query)
    @Cached(name = EduCache.EDU_CAN_ENROLL, key = "#vo.studentEnrollPreId", cacheType = CacheType.BOTH, expire = 3600, localExpire = 20)
    public EduStudentEnrollPreVO getPreDetail(EduStudentEnrollPreKeyVO vo) {
        if(vo.getYear()==null){
            vo.setYear(eduHelper.thisYear());
        }
        EduStudentEnrollPreVO studentEnrollPreVO = getPreById(vo);
        //错误原因提交的时候有可能会影响后端关键字过滤器
        studentEnrollPreVO.setBeforeRemark("");
        studentEnrollPreVO.setHouseholdSyncRemark("");
        studentEnrollPreVO.setHouseSyncRemark("");
        studentEnrollPreVO.setCbSyncRemark("");
        studentEnrollPreVO.setQySyncRemark("");
        studentEnrollPreVO.setJzzSyncRemark("");
        studentEnrollPreVO.setNetsignSyncRemark("");
        studentEnrollPreVO.setFamilyRemark("");
        searchGuardians(studentEnrollPreVO);
        dictHelper.valueToName(studentEnrollPreVO, Arrays.asList(EduEnrollPreDictEnum.values()));
        if(StringUtils.isNotBlank(studentEnrollPreVO.getAreaCode())){
            studentEnrollPreVO.setAreaName(dictHelper.getAreaNameByCode(studentEnrollPreVO.getAreaCode()));
        }
        if (StringUtils.isBlank(studentEnrollPreVO.getAreaCode())){
            studentEnrollPreVO.setAreaCode(eduHelper.thisAreaCode());
        }
        if (StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(studentEnrollPreVO.getAreaCode());
        }
        // 查询学校信息
        if (StringUtils.isNotBlank(studentEnrollPreVO.getSchoolId())) {
            EduSchoolVO school = eduSchoolService.getDetail(studentEnrollPreVO.getSchoolId());
            if (school != null) {
                studentEnrollPreVO.setSchoolName(school.getSchoolName());
            }
        }
        if (StringUtils.isNotBlank(studentEnrollPreVO.getOrgId())) {
            EduSchoolVO school = eduSchoolService.getDetail(studentEnrollPreVO.getOrgId());
            if (school != null) {
                studentEnrollPreVO.setCjSchoolName(school.getSchoolName());
            }
        }

        //获取预报名信息
        EduStudentEnrollBeforeQueryVO beforeQueryVO = new EduStudentEnrollBeforeQueryVO();
        beforeQueryVO.setStudentEnrollPreId(studentEnrollPreVO.getStudentEnrollPreId());
        beforeQueryVO.setYear(studentEnrollPreVO.getYear());
        //有查询过历史数据
        PageInfo<EduStudentEnrollBeforeVO> beforeVOPageInfo = this.queryBeforePageList(beforeQueryVO);
        studentEnrollPreVO.setEnrollBeforeList(beforeVOPageInfo.getList());
        if (!CollectionUtils.isEmpty(beforeVOPageInfo.getList())) {
            List<String> houseIdList = new ArrayList<>();
            for (EduStudentEnrollBeforeVO beforeVO : beforeVOPageInfo.getList()) {
                if (BoolEnum.TRUE.getType().equalsIgnoreCase(beforeVO.getSpecialFlag())) {
                    if (StringUtils.isNotBlank(beforeVO.getHouseId())) {
                        houseIdList.add(beforeVO.getHouseId());
                    }
                }
            }
            if (!CollectionUtils.isEmpty(houseIdList)) {
                //查询房产历史表
                List<EduHouse> eduHouseList;
                Boolean houseHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), HOUSE_TABLE);
                if (!houseHistoryFlag) {
                    QueryWrapper<EduHouse> houseQueryWrapper = new QueryWrapper<>();
                    houseQueryWrapper.lambda().in(EduHouse::getHouseId, houseIdList);
                    eduHouseList = eduHouseService.list(houseQueryWrapper);
                }else {
                    QueryWrapper<EduhHouse> eduhHouseQueryWrapper = new QueryWrapper<>();
                    eduhHouseQueryWrapper.lambda().in(EduhHouse::getHouseId, houseIdList);
                    List<EduhHouse> eduhHouses = eduhHouseService.list(eduhHouseQueryWrapper);
                    //解密
                    for (EduhHouse eduhHouse : eduhHouses) {
                        if ("1".equals(eduhHouse.getEncryptFlag())){
                            eduhHouseService.decrypt(eduhHouse);
                        }
                    }
                    eduHouseList = Convert.toList(EduHouse.class, eduhHouses);
                }
                List<EduHouseVO> houseTstdVOList = new ArrayList<>();
                //查询房产详情历史表
                List<EduHouseDetail> detailList;
                Boolean houseDetailHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), HOUSE_TABLE_DETAIL);
                if (!houseDetailHistoryFlag){
                    QueryWrapper<EduHouseDetail> detailQueryWrapper = new QueryWrapper<>();
                    detailQueryWrapper.lambda()
                            .select(EduHouseDetail::getIdcard, EduHouseDetail::getFullName, EduHouseDetail::getHouseId, EduHouseDetail::getRealProperty, EduHouseDetail::getStatus)
                            .in(EduHouseDetail::getHouseId, houseIdList);
                    detailList = eduHouseDetailService.list(detailQueryWrapper);
                }else {
                    QueryWrapper<EduhHouseDetail> eduhHouseDetailQueryWrapper = new QueryWrapper<>();
                    eduhHouseDetailQueryWrapper.lambda()
                            .select(EduhHouseDetail::getIdcard, EduhHouseDetail::getFullName, EduhHouseDetail::getHouseId, EduhHouseDetail::getRealProperty, EduhHouseDetail::getStatus)
                            .in(EduhHouseDetail::getHouseId, houseIdList);
                    List<EduhHouseDetail> eduhHouseDetails = eduhHouseDetailService.list(eduhHouseDetailQueryWrapper);
                    //判断是否加密，解密
                    for (EduhHouseDetail eduhHouseDetail : eduhHouseDetails) {
                        if ("1".equals(eduhHouseDetail.getEncryptFlag())){
                            if (StringUtils.isNotBlank(eduhHouseDetail.getRealProperty())){
                                eduhHouseDetail.setRealProperty(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getRealProperty()));
                            }
                            if (StringUtils.isNotBlank(eduhHouseDetail.getObligee())){
                                eduhHouseDetail.setObligee(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getObligee()));
                            }
                            if (StringUtils.isNotBlank(eduhHouseDetail.getIdcard())){
                                eduhHouseDetail.setIdcard(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getIdcard()));
                            }
                            if (StringUtils.isNotBlank(eduhHouseDetail.getFullName())){
                                eduhHouseDetail.setFullName(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getFullName()));
                            }
                        }
                    }
                    detailList = Convert.toList(EduHouseDetail.class, eduhHouseDetails);
                }
                Map<String, List<EduHouseDetail>> detailMap = new HashMap<>();
                if (!CollectionUtils.isEmpty(detailList)) {
                    detailMap = detailList.stream().collect(Collectors.groupingBy(EduHouseDetail::getHouseId));
                }
                for (EduHouse eduHouse : eduHouseList) {
                    EduHouseVO houseVO = Convert.convert(EduHouseVO.class, eduHouse);
                    houseVO.setRealPropertyDetails(eduHouse.getRealProperty());
                    List<EduHouseDetail> details = detailMap.get(eduHouse.getHouseId());
                    if (!CollectionUtils.isEmpty(details)) {
                        houseVO.setDetailList(Convert.toList(EduHouseDetailVO.class, details));
                        houseTstdVOList.add(houseVO);
                    }

                }
                studentEnrollPreVO.setHouseTstdList(houseTstdVOList);

            }
        }
        //获取户籍信息
        studentEnrollPreVO.setHouseholdFmFlag(false);
        //查询户籍历史表
        List<EduHousehold> list;
        Boolean householdHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), HOUSEHOLD_TABLE);
        String idcard = studentEnrollPreVO.getIdcard();
        String idcardHistory = CommonSecureUtil.sm4Encrypt(studentEnrollPreVO.getIdcard());//加密后的身份证
        if (!householdHistoryFlag) {
            QueryWrapper<EduHousehold> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduHousehold::getIdcard, idcard)
                    .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType())
                    .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduHousehold::getYear, studentEnrollPreVO.getYear())
                    .orderByDesc(EduHousehold::getQysj);
            list = eduHouseholdService.list(queryWrapper);
        }else {
            // 迁移过后，判断是否加密
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), HOUSEHOLD_TABLE));
            QueryWrapper<EduhHousehold> queryWrapperHistory =  new QueryWrapper<>();
            queryWrapperHistory.lambda()
                    .eq(EduhHousehold::getStatus, BoolEnum.TRUE.getType())
                    .eq(EduhHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduhHousehold::getYear, studentEnrollPreVO.getYear())
                    .orderByDesc(EduhHousehold::getQysj);
            //如果加密，使用加密的身份证
            if (encryptFlag) {
                queryWrapperHistory.lambda().eq(EduhHousehold::getIdcard, idcardHistory);
            }else{
                queryWrapperHistory.lambda().eq(EduhHousehold::getIdcard, idcard);
            }
            List<EduhHousehold> eduhHouseholdList = eduhHouseholdService.list(queryWrapperHistory);
            for (EduhHousehold eduhHousehold : eduhHouseholdList) {
                if ("1".equals(eduhHousehold.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(eduhHousehold.getIdcard())){
                        eduhHousehold.setIdcard(CommonSecureUtil.sm4Decrypt(eduhHousehold.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getFullName())){
                        eduhHousehold.setFullName(CommonSecureUtil.sm4Decrypt(eduhHousehold.getFullName()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getBeforeName())){
                        eduhHousehold.setBeforeName(CommonSecureUtil.sm4Decrypt(eduhHousehold.getBeforeName()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getAddress())){
                        eduhHousehold.setAddress(CommonSecureUtil.sm4Decrypt(eduhHousehold.getAddress()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getHouseholdPlace())){
                        eduhHousehold.setHouseholdPlace(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholdPlace()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getHouseholder())){
                        eduhHousehold.setHouseholder(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholder()));
                    }
                    if (StringUtils.isNotBlank(eduhHousehold.getHouseholderIdcard())){
                        eduhHousehold.setHouseholderIdcard(CommonSecureUtil.sm4Decrypt(eduhHousehold.getHouseholderIdcard()));
                    }
                }
            }
            list = Convert.toList(EduHousehold.class, eduhHouseholdList);
        }
        boolean hzhjFlag=false;
        if (!CollectionUtils.isEmpty(list)) {
            EduHouseholdVO houseHoldVO = Convert.convert(EduHouseholdVO.class, list.get(0));
            if ("330783".equals(houseHoldVO.getAreaCode())) {
                studentEnrollPreVO.setHouseHoldVO(houseHoldVO);
                studentEnrollPreVO.setHouseholdAddress(houseHoldVO.getAddress());
                studentEnrollPreVO.setAccountType(houseHoldVO.getAccountType());
                studentEnrollPreVO.setRelation(houseHoldVO.getRelation());
                if (StringUtils.isBlank(studentEnrollPreVO.getHouseholdPlace())) {
                    studentEnrollPreVO.setHouseholdPlace(houseHoldVO.getAddress());
                }
                hzhjFlag=true;
            }
        }
        if(!hzhjFlag){
            List<String> fmIdcardList=new ArrayList<>();
            if(StringUtils.isNotBlank(studentEnrollPreVO.getMotherIdcard())){
                fmIdcardList.add(studentEnrollPreVO.getMotherIdcard());
            }
            if(StringUtils.isNotBlank(studentEnrollPreVO.getFatherIdcard())){
                fmIdcardList.add(studentEnrollPreVO.getFatherIdcard());
            }
            LambdaQueryWrapper<EduHousehold> fmhouseholdQuery=new LambdaQueryWrapper<>();
            fmhouseholdQuery.in(EduHousehold::getIdcard, fmIdcardList)
                    .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType())
                    .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduHousehold::getAreaCode, studentEnrollPreVO.getAreaCode())
                    .eq(EduHousehold::getYear, studentEnrollPreVO.getYear());
            if(eduHouseholdService.count(fmhouseholdQuery)>0){
                studentEnrollPreVO.setHouseholdFmFlag(true);
            }
        }
        //获取房产信息
        //获取本人以及父母名下房产信息
        List<String> idcardList = new ArrayList<>();//没有加密的身份证集合
        List<String> idcardSm4List =  new ArrayList<>();//加密身份证集合
        if (StringUtils.isNotBlank(studentEnrollPreVO.getIdcard())) {
            idcardList.add(studentEnrollPreVO.getIdcard());
        }
        if (StringUtils.isNotBlank(studentEnrollPreVO.getFatherIdcard())) {
            idcardList.add(studentEnrollPreVO.getFatherIdcard());
        }
        if (StringUtils.isNotBlank(studentEnrollPreVO.getMotherIdcard())) {
            idcardList.add(studentEnrollPreVO.getMotherIdcard());
        }
        if (!CollectionUtils.isEmpty(idcardList)) {
            // 身份证加密
            for (String idCard : idcardList) {
                idcardSm4List.add(CommonSecureUtil.sm4Encrypt(idCard));
            }
        }
        //查询房产历史表
        List<EduHouse> houseList;
        Boolean houseHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), HOUSE_TABLE);
        if (!houseHistoryFlag) {
            houseList = eduHouseService.getHouseByAllIdcard(idcardList, studentEnrollPreVO.getYear(), null, null);
        }else {
            // 迁移过后，判断是否加密
            List<EduhHouse> eduhHouseList;
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), HOUSE_TABLE));
            //如果加密，把查询条件加密
            if (encryptFlag) {
                eduhHouseList = eduHouseService.getHouseByAllIdcardHistory(idcardSm4List, studentEnrollPreVO.getYear(), null, null);
            }else {
                eduhHouseList = eduHouseService.getHouseByAllIdcardHistory(idcardList, studentEnrollPreVO.getYear(), null, null);
            }
            //解密
            for (EduhHouse eduhHouse : eduhHouseList) {
                if ("1".equals(eduhHouse.getEncryptFlag())){
                    eduhHouseService.decrypt(eduhHouse);
                }
            }
            houseList = Convert.toList(EduHouse.class, eduhHouseList);
        }
        if (!CollectionUtils.isEmpty(houseList)) {
            List<EduHouseVO> houseVOList = new ArrayList<>();
            List<String> houseIdList = houseList.stream().map(EduHouse::getHouseId).collect(Collectors.toList());
            //查询房产详情历史表
            List<EduHouseDetail> detailList;
            Boolean houseDetailHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), HOUSE_TABLE_DETAIL);
            if (!houseDetailHistoryFlag){
                QueryWrapper<EduHouseDetail> detailQueryWrapper = new QueryWrapper<>();
                detailQueryWrapper.lambda()
                        .select(EduHouseDetail::getIdcard, EduHouseDetail::getFullName, EduHouseDetail::getHouseId, EduHouseDetail::getRealProperty, EduHouseDetail::getStatus)
                        .in(EduHouseDetail::getHouseId, houseIdList);
                detailList = eduHouseDetailService.list(detailQueryWrapper);
            }else {
                QueryWrapper<EduhHouseDetail> eduhHouseDetailQueryWrapper = new QueryWrapper<>();
                eduhHouseDetailQueryWrapper.lambda()
                        .select(EduhHouseDetail::getIdcard, EduhHouseDetail::getFullName, EduhHouseDetail::getHouseId, EduhHouseDetail::getRealProperty, EduhHouseDetail::getStatus)
                        .in(EduhHouseDetail::getHouseId, houseIdList);
                List<EduhHouseDetail> eduhHouseDetails = eduhHouseDetailService.list(eduhHouseDetailQueryWrapper);
                //判断是否加密，解密
                for (EduhHouseDetail eduhHouseDetail : eduhHouseDetails) {
                    if ("1".equals(eduhHouseDetail.getEncryptFlag())){
                        if (StringUtils.isNotBlank(eduhHouseDetail.getRealProperty())){
                            eduhHouseDetail.setRealProperty(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getRealProperty()));
                        }
                        if (StringUtils.isNotBlank(eduhHouseDetail.getObligee())){
                            eduhHouseDetail.setObligee(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getObligee()));
                        }
                        if (StringUtils.isNotBlank(eduhHouseDetail.getIdcard())){
                            eduhHouseDetail.setIdcard(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getIdcard()));
                        }
                        if (StringUtils.isNotBlank(eduhHouseDetail.getFullName())){
                            eduhHouseDetail.setFullName(CommonSecureUtil.sm4Decrypt(eduhHouseDetail.getFullName()));
                        }
                    }
                }
                detailList = Convert.toList(EduHouseDetail.class, eduhHouseDetails);
            }
            Map<String,List<EduHouseDetail>> detailMap=new HashMap<>();
            if(!CollectionUtils.isEmpty(detailList)){
                detailMap=detailList.stream().collect(Collectors.groupingBy(EduHouseDetail::getHouseId));
            }
            for (EduHouse eduHouse : houseList) {
                EduHouseVO houseVO = Convert.convert(EduHouseVO.class, eduHouse);
                houseVO.setRealPropertyDetails(eduHouse.getRealProperty());
                List<EduHouseDetail> details=detailMap.get(eduHouse.getHouseId());
                if(!CollectionUtils.isEmpty(details)){
                    houseVO.setDetailList(Convert.toList(EduHouseDetailVO.class,details));
                    houseVOList.add(houseVO);

                }

            }
            studentEnrollPreVO.setHouseList(houseVOList);
        }
        //获取参保信息
        //判断是否迁移
        List<EduSocialSecurity> socialSecurityList;
        boolean socialHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), STUDENT_SOCIAL_SECURITY);
        // 根据是否查询历史表，调用不同方法
        if (!socialHistoryFlag) {
            QueryWrapper<EduSocialSecurity> securityQueryWrapper = new QueryWrapper<>();
            securityQueryWrapper.lambda().eq(EduSocialSecurity::getYear, studentEnrollPreVO.getYear())
                    .eq(EduSocialSecurity::getAab301, studentEnrollPreVO.getAreaCode())
                    .in(EduSocialSecurity::getAac147, idcardList)
                    .orderByAsc(EduSocialSecurity::getAac147).orderByAsc(EduSocialSecurity::getAae140).orderByAsc(EduSocialSecurity::getAae030);
            socialSecurityList= eduSocialSecurityService.list(securityQueryWrapper);
        }else {
            QueryWrapper<EduhSocialSecurity> eduhSecurityQueryWrapper = new QueryWrapper<>();
            eduhSecurityQueryWrapper.lambda().eq(EduhSocialSecurity::getYear, studentEnrollPreVO.getYear())
                    .eq(EduhSocialSecurity::getAab301, studentEnrollPreVO.getAreaCode())
                    .orderByAsc(EduhSocialSecurity::getAac147).orderByAsc(EduhSocialSecurity::getAae140).orderByAsc(EduhSocialSecurity::getAae030);
            // 迁移过后，判断是否加密
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), STUDENT_SOCIAL_SECURITY));
            //如果加密，把查询条件加密
            if (encryptFlag) {
                eduhSecurityQueryWrapper.lambda().in(EduhSocialSecurity::getAac147,idcardSm4List );
            }else {
                eduhSecurityQueryWrapper.lambda().in(EduhSocialSecurity::getAac147, idcardList);
            }
            List<EduhSocialSecurity> eduhSocialSecurityList = eduhSocialSecurityService.list(eduhSecurityQueryWrapper);
            for (EduhSocialSecurity eduhSocialSecurity : eduhSocialSecurityList) {
                if ("1".equals(eduhSocialSecurity.getEncryptFlag())){
                    if (StringUtils.isNotBlank(eduhSocialSecurity.getAac003())) {
                        eduhSocialSecurity.setAac003(CommonSecureUtil.sm4Decrypt(eduhSocialSecurity.getAac003()));
                    }
                    if (StringUtils.isNotBlank(eduhSocialSecurity.getAac147())) {
                        eduhSocialSecurity.setAac147(CommonSecureUtil.sm4Decrypt(eduhSocialSecurity.getAac147()));
                    }
                }
            }
            socialSecurityList = Convert.toList(EduSocialSecurity.class, eduhSocialSecurityList);
        }
        if (!CollectionUtils.isEmpty(socialSecurityList)) {
            List<EduSocialSecurityVO> cbVOList = Convert.toList(EduSocialSecurityVO.class, socialSecurityList);
            for(EduSocialSecurityVO eduSocialSecurityVO:cbVOList){
                eduSocialSecurityVO.setAae140Name(dictHelper.getValue("AAE140",eduSocialSecurityVO.getAae140()));
                eduSocialSecurityVO.setAab301Name(dictHelper.getValue("AREA",eduSocialSecurityVO.getAab301()));
                if("1".equalsIgnoreCase(eduSocialSecurityVO.getAac008())){
                    if("1".equalsIgnoreCase(eduSocialSecurityVO.getAac031())){
                        eduSocialSecurityVO.setStatus("1");
                        eduSocialSecurityVO.setStatusName("正常参保");
                    }else{
                        eduSocialSecurityVO.setStatus("2");
                        eduSocialSecurityVO.setStatusName("参保中断");
                    }
                }else{
                    eduSocialSecurityVO.setStatus("3");
                    eduSocialSecurityVO.setStatusName("参保终止");
                }
            }
            studentEnrollPreVO.setCbList(cbVOList);
        }
        //获取网签信息
        //根据任务判断是否当前年度处理过迁移数据
        List<EduNetsign> netsignList;
        Boolean netsignHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), EDU_NETSIGN);
        if (!netsignHistoryFlag) {
            QueryWrapper<EduNetsign> netsignQueryWrapper = new QueryWrapper<>();
            netsignQueryWrapper.lambda().eq(EduNetsign::getYear, studentEnrollPreVO.getYear())
                    .in(EduNetsign::getIdcard, idcardList).orderByDesc(EduNetsign::getStatus).orderByAsc(EduNetsign::getBasj);
            netsignList = eduNetsignService.list(netsignQueryWrapper);
        }else {
            QueryWrapper<EduhNetsign> eduhNetsignQueryWrapper = new QueryWrapper<>();
            eduhNetsignQueryWrapper.lambda()
                    .eq(EduhNetsign::getYear, studentEnrollPreVO.getYear())
                    .orderByDesc(EduhNetsign::getStatus)
                    .orderByAsc(EduhNetsign::getBasj);
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), EDU_NETSIGN));
            if (encryptFlag) {
                eduhNetsignQueryWrapper.lambda().in(EduhNetsign::getIdcard,idcardSm4List );
            }else {
                eduhNetsignQueryWrapper.lambda().in(EduhNetsign::getIdcard, idcardList);
            }
            List<EduhNetsign> EduhNetsign = eduhNetsignService.list(eduhNetsignQueryWrapper);
            for (EduhNetsign eduhNetsign : EduhNetsign) {
                if ("1".equals(eduhNetsign.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(eduhNetsign.getIdcard())){
                        eduhNetsign.setIdcard(CommonSecureUtil.sm4Decrypt(eduhNetsign.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduhNetsign.getXm())){
                        eduhNetsign.setXm(CommonSecureUtil.sm4Decrypt(eduhNetsign.getXm()));
                    }
                    if (StringUtils.isNotBlank(eduhNetsign.getDz())){
                        eduhNetsign.setDz(CommonSecureUtil.sm4Decrypt(eduhNetsign.getDz()));
                    }
                }
            }
            netsignList = Convert.toList(EduNetsign.class, EduhNetsign);
        }

        if (!CollectionUtils.isEmpty(netsignList)) {
            List<EduNetsignVO> netsignVOList = Convert.toList(EduNetsignVO.class, netsignList);
            for (EduNetsignVO eduNetsignVO : netsignVOList) {
                if (StringUtils.isNotBlank(eduNetsignVO.getSchoolId())) {
                    EduSchoolVO eduSchool = eduSchoolService.getDetail(eduNetsignVO.getSchoolId());
                    if (eduSchool != null) {
                        eduNetsignVO.setSchoolName(eduSchool.getSchoolName());
                    }

                }
            }
            studentEnrollPreVO.setWqList(netsignVOList);
        }
        //获取学籍信息
        //根据任务判断是否当前年度处理过迁移数据
        EduStudentStatus eduStudentStatus;
        Boolean statusHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),EDU_STUDENT_STATUS);
        if (!statusHistoryFlag) {
            QueryWrapper<EduStudentStatus> statusQueryWrapper = new QueryWrapper<>();
            statusQueryWrapper.lambda().eq(EduStudentStatus::getYear, studentEnrollPreVO.getYear())
                    .eq(EduStudentStatus::getIdcard, idcard);
            eduStudentStatus = eduStudentStatusService.getOne(statusQueryWrapper, false);
        }else {
            QueryWrapper<EduhStudentStatus> eduhStatusQueryWrapper = new QueryWrapper<>();
            eduhStatusQueryWrapper.lambda()
                    .eq(EduhStudentStatus::getYear, studentEnrollPreVO.getYear());
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), EDU_STUDENT_STATUS));
            if (encryptFlag) {
                eduhStatusQueryWrapper.lambda().eq(EduhStudentStatus::getIdcard,idcardHistory );
            }else {
                eduhStatusQueryWrapper.lambda().eq(EduhStudentStatus::getIdcard, idcard);
            }
            EduhStudentStatus eduhStudentStatus = eduhStudentStatusService.getOne(eduhStatusQueryWrapper, false);
            if (eduhStudentStatus != null) {
                if ("1".equals(eduhStudentStatus.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(eduhStudentStatus.getIdcard())) {
                        eduhStudentStatus.setIdcard(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentStatus.getFullName())) {
                        eduhStudentStatus.setFullName(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getFullName()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentStatus.getFatherIdcard())) {
                        eduhStudentStatus.setFatherIdcard(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getFatherIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentStatus.getFatherName())) {
                        eduhStudentStatus.setFatherName(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getFatherName()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentStatus.getMotherName())) {
                        eduhStudentStatus.setMotherName(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getMotherName()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentStatus.getMotherIdcard())) {
                        eduhStudentStatus.setMotherIdcard(CommonSecureUtil.sm4Decrypt(eduhStudentStatus.getMotherIdcard()));
                    }
                }
            }
            eduStudentStatus = Convert.convert(EduStudentStatus.class, eduhStudentStatus);
        }
        if (eduStudentStatus != null) {
            EduStudentStatusVO studentStatusVO = Convert.convert(EduStudentStatusVO.class, eduStudentStatus);
            if (StringUtils.isNotBlank(studentStatusVO.getSchoolId())) {
                EduSchoolVO eduSchool = eduSchoolService.getDetail(studentStatusVO.getSchoolId());
                if (eduSchool != null) {
                    studentStatusVO.setSchoolName(eduSchool.getSchoolName());
                }

            }
            studentEnrollPreVO.setStudentStatusVO(studentStatusVO);
        }
        //获取城区E
        QueryWrapper<EduAppointStudent> appointStudentQueryWrapper = new QueryWrapper<>();
        appointStudentQueryWrapper.lambda().eq(EduAppointStudent::getYear, studentEnrollPreVO.getYear())
                .eq(EduAppointStudent::getStatus, BoolEnum.TRUE.getType())
                .eq(EduAppointStudent::getIdcard, idcard);
        List<EduAppointStudent> eduAppointStudentList = eduAppointStudentService.list(appointStudentQueryWrapper);
        if (!CollectionUtils.isEmpty(eduAppointStudentList)) {
            List<EduAppointStudentVO> cqeList = new ArrayList<>();
            for (EduAppointStudent eduAppointStudent : eduAppointStudentList) {
                EduAppointStudentVO eduAppointStudentVO = Convert.convert(EduAppointStudentVO.class, eduAppointStudent);
                if (StringUtils.isNotBlank(eduAppointStudentVO.getSchoolId())) {
                    EduSchoolVO eduSchool = eduSchoolService.getDetail(eduAppointStudentVO.getSchoolId());
                    if (eduSchool != null) {
                        BeanUtil.copyProperties(eduSchool, eduAppointStudentVO);
                    }

                }
                cqeList.add(eduAppointStudentVO);
            }
            studentEnrollPreVO.setAppointFlag(BoolEnum.TRUE.getType());
            studentEnrollPreVO.setCqeList(cqeList);
        } else {
            studentEnrollPreVO.setAppointFlag(BoolEnum.FALSE.getType());
        }
        //获取直升班
        QueryWrapper<EduPrivateAppointStudent> privateAppointStudentQueryWrapper = new QueryWrapper<>();
        privateAppointStudentQueryWrapper.lambda().eq(EduPrivateAppointStudent::getYear, studentEnrollPreVO.getYear())
                .eq(EduPrivateAppointStudent::getStatus, BoolEnum.TRUE.getType())
                .eq(EduPrivateAppointStudent::getIdcard, idcard);
        EduPrivateAppointStudent eduPrivateAppointStudent = eduPrivateAppointStudentService.getOne(privateAppointStudentQueryWrapper, false);
        if (eduPrivateAppointStudent != null) {
            EduPrivateAppointStudentVO promotionPreVO = Convert.convert(EduPrivateAppointStudentVO.class, eduPrivateAppointStudent);
            if (StringUtils.isNotBlank(promotionPreVO.getSchoolId())) {
                EduSchoolVO eduSchool = eduSchoolService.getDetail(promotionPreVO.getSchoolId());
                if (eduSchool != null) {
                    BeanUtil.copyProperties(eduSchool, promotionPreVO);
                }
            }
            studentEnrollPreVO.setPrivateAppointFlag(BoolEnum.TRUE.getType());
            studentEnrollPreVO.setZsbVO(promotionPreVO);
        } else {
            studentEnrollPreVO.setPrivateAppointFlag(BoolEnum.FALSE.getType());
        }
        //开办企业
        //根据任务判断是否当前年度处理过迁移数据
        List<EduCompany> companyList;
        Boolean companyHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),EDU_COMPANY);
        if (!companyHistoryFlag) {
            QueryWrapper<EduCompany> companyQueryWrapper = new QueryWrapper<>();
            companyQueryWrapper.lambda().eq(EduCompany::getYear, studentEnrollPreVO.getYear())
                    .in(EduCompany::getFrZjhm, idcardList);
            companyList = eduCompanyService.list(companyQueryWrapper);
        }else{
            QueryWrapper<EduhCompany> eduhCompanyQueryWrapper = new QueryWrapper<>();
            eduhCompanyQueryWrapper.lambda().eq(EduhCompany::getYear, studentEnrollPreVO.getYear());
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), EDU_COMPANY));
            if (encryptFlag) {
                eduhCompanyQueryWrapper.lambda().eq(EduhCompany::getFrZjhm,idcardHistory );
            }else {
                eduhCompanyQueryWrapper.lambda().eq(EduhCompany::getFrZjhm, idcard);
            }
            List<EduhCompany> eduhCompanyList = eduhCompanyService.list(eduhCompanyQueryWrapper);
            for (EduhCompany eduCompanyVO : eduhCompanyList) {
                if ("1".equals(eduCompanyVO.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(eduCompanyVO.getTyxydm())) {
                        eduCompanyVO.setTyxydm(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getTyxydm()));
                    }
                    if (StringUtils.isNotBlank(eduCompanyVO.getDh())) {
                        eduCompanyVO.setDh(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getDh()));
                    }
                    if (StringUtils.isNotBlank(eduCompanyVO.getFrmc())) {
                        eduCompanyVO.setFrmc(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getFrmc()));
                    }
                    if (StringUtils.isNotBlank(eduCompanyVO.getFrZjhm())) {
                        eduCompanyVO.setFrZjhm(CommonSecureUtil.sm4Decrypt(eduCompanyVO.getFrZjhm()));
                    }
                }
            }
            companyList = Convert.toList(EduCompany.class, eduhCompanyList);
        }
        if (!CollectionUtils.isEmpty(companyList)) {
            List<EduCompanyVO> qyVOList = Convert.toList(EduCompanyVO.class, companyList);
            studentEnrollPreVO.setQyList(qyVOList);
        }
        //居住证信息
        List<EduLivePlace> livePlaceList;
        Boolean placeHistoryFlag = eduDataTaskDetailService.verifyQueryHistory(vo.getYear(),EDU_LIVE_PLACE);
        if (!placeHistoryFlag) {
            QueryWrapper<EduLivePlace> livePlaceQueryWrapper = new QueryWrapper<>();
            livePlaceQueryWrapper.lambda().eq(EduLivePlace::getYear, studentEnrollPreVO.getYear())
                    .in(EduLivePlace::getSfzh, idcardList).orderByAsc(EduLivePlace::getSfzh);
            livePlaceList = eduLivePlaceService.list(livePlaceQueryWrapper);
        }else {
            QueryWrapper<EduhLivePlace> eduhLivePlaceQueryWrapper = new QueryWrapper<>();
            eduhLivePlaceQueryWrapper.lambda().eq(EduhLivePlace::getYear, studentEnrollPreVO.getYear());
            Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), EDU_LIVE_PLACE));
            if (encryptFlag) {
                eduhLivePlaceQueryWrapper.lambda().in(EduhLivePlace::getSfzh, idcardHistory);
            }else {
                eduhLivePlaceQueryWrapper.lambda().in(EduhLivePlace::getSfzh, idcardList);
            }
            List<EduhLivePlace> eduhLivePlaceList = eduhLivePlaceService.list(eduhLivePlaceQueryWrapper);
            for (EduhLivePlace EduhLivePlace : eduhLivePlaceList) {
                //对字段进行解密
                if (BoolEnum.TRUE.getType().equalsIgnoreCase(EduhLivePlace.getEncryptFlag())){
                    eduhLivePlaceService.decrypt(EduhLivePlace);
                }
            }
            livePlaceList = Convert.toList(EduLivePlace.class, eduhLivePlaceList);
        }
        if (!CollectionUtils.isEmpty(livePlaceList)) {
            List<EduLivePlaceVO> livePlaceVOList = Convert.toList(EduLivePlaceVO.class, livePlaceList);
            studentEnrollPreVO.setJzzList(livePlaceVOList);
        }
        studentEnrollPreVO.setBmFlag(checkEnroll(studentEnrollPreVO.getIdcard(),studentEnrollPreVO.getYear()));
        // 补报是否需要之前有报名记录
        CommonVO commonVO=new CommonVO();
        commonVO.setAreaCode(vo.getAreaCode());
        commonVO.setParamKey("edu_bb_check_enroll");
        String bbCheckEnrollStr=commonIntegration.getValueByKeyAndArea(commonVO);
        if ("1".equals(bbCheckEnrollStr)||"true".equals(bbCheckEnrollStr)) {
            studentEnrollPreVO.setHasBmType(hasEnroll(studentEnrollPreVO.getIdcard(), studentEnrollPreVO.getYear())?"1":"0");
        }else{
            studentEnrollPreVO.setHasBmType("2");
        }
        return studentEnrollPreVO;
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0017", title = "预报名管理获取房产数据", funcType = FuncTypeEnum.query)
    public void getFcByPreId(EduStudentEnrollPreKeyVO vo) {
        EduHousePreVO preVO = new EduHousePreVO();
        preVO.setStudentEnrollPreId(vo.getStudentEnrollPreId());
        preVO.setCheckBm(true);
        preVO.setReqIp(vo.getReqIp());
        eduHouseIntegration.saveHouseByPre(preVO);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0027", title = "预报名管理获取房产数据不校验是否报名", funcType = FuncTypeEnum.query)
    public void getFcByPreIdNoClick(EduStudentEnrollPreKeyVO vo) {
        EduHousePreVO preVO = new EduHousePreVO();
        preVO.setStudentEnrollPreId(vo.getStudentEnrollPreId());
        preVO.setCheckBm(false);
        preVO.setReqIp(vo.getReqIp());
        eduHouseIntegration.saveHouseByPre(preVO);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0018", title = "预报名管理获取户籍数据", funcType = FuncTypeEnum.query)
    public void getHjByPreId(HouseHoldSaveVO vo) {
        if(StringUtils.isBlank(vo.getStudentEnrollPreId())){
            throw new AppException("预采集id不能为空");
        }
        EduStudentEnrollPreKeyVO keyVO=Convert.convert(EduStudentEnrollPreKeyVO.class,vo);
        EduStudentEnrollPreVO preVO = this.getPreById(keyVO);
        HouseHoldSaveVO saveVO=new HouseHoldSaveVO();
        saveVO.setAreaCode(preVO.getAreaCode());
        saveVO.setIdcard(preVO.getIdcard());
        saveVO.setLocalFlag(vo.getLocalFlag());
        saveVO.setStudentEnrollPreId(vo.getStudentEnrollPreId());
        saveVO.setReqIp(vo.getReqIp());
        eduHouseholdIntegration.saveHouseHoldData(saveVO);
        if(StringUtils.isNotBlank(preVO.getFatherIdcard())) {
            HouseHoldSaveVO savefqVO = new HouseHoldSaveVO();
            savefqVO.setAreaCode(preVO.getAreaCode());
            savefqVO.setIdcard(preVO.getFatherIdcard());
            savefqVO.setLocalFlag(vo.getLocalFlag());
            savefqVO.setStudentEnrollPreId(vo.getStudentEnrollPreId());
            savefqVO.setReqIp(vo.getReqIp());
            eduHouseholdIntegration.saveHouseHoldData(savefqVO);
        }
        if(StringUtils.isNotBlank(preVO.getMotherIdcard())) {
            HouseHoldSaveVO saveMqVO = new HouseHoldSaveVO();
            saveMqVO.setAreaCode(preVO.getAreaCode());
            saveMqVO.setIdcard(preVO.getMotherIdcard());
            saveMqVO.setLocalFlag(vo.getLocalFlag());
            saveMqVO.setStudentEnrollPreId(vo.getStudentEnrollPreId());
            saveMqVO.setReqIp(vo.getReqIp());
            eduHouseholdIntegration.saveHouseHoldData(saveMqVO);
        }
        if(StringUtils.isNotBlank(preVO.getIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(preVO.getIdcard());
        }
        if(StringUtils.isNotBlank(preVO.getFatherIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(preVO.getFatherIdcard());
        }
        if(StringUtils.isNotBlank(preVO.getMotherIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(preVO.getMotherIdcard());
        }
        eduEnrollClearCacheHelper.clearCachePreBefore(preVO.getStudentEnrollPreId());
    }

    /**
     * 查询监护人信息
     *
     * @param enrollPre
     * @return
     */
    private void searchGuardians(EduStudentEnrollPreVO enrollPre) {
        String studentEnrollPreId = enrollPre.getStudentEnrollPreId();
        if (StringUtils.isNotBlank(studentEnrollPreId)) {
            QueryWrapper<EduStudentEnrollFamily> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduStudentEnrollFamily::getStudentEnrollPreId, studentEnrollPreId);
            List<EduStudentEnrollFamily> familyList = eduStudentEnrollFamilyService.list(queryWrapper);
            if(CollectionUtils.isEmpty(familyList)){
                List<EduStudentEnrollFamilyVO> guardians = new ArrayList<>();
                EduStudentEnrollFamilyVO familyVOFather = new EduStudentEnrollFamilyVO();
                EduStudentEnrollFamilyVO familyVOMother = new EduStudentEnrollFamilyVO();
                if(!StringUtils.isBlank(enrollPre.getFatherIdcard())){
                    familyVOFather.setIdcard(enrollPre.getFatherIdcard());
                    familyVOFather.setFullName(enrollPre.getFatherName());
                    familyVOFather.setCardType(enrollPre.getFatherCardType());
                    familyVOFather.setWork(enrollPre.getFatherWork());
                    familyVOFather.setCellphone(enrollPre.getFatherCellphone());
                    familyVOFather.setRelationshipType("1");
                }
                if(!StringUtils.isBlank(enrollPre.getMotherIdcard())){
                    familyVOMother.setIdcard(enrollPre.getMotherIdcard());
                    familyVOMother.setFullName(enrollPre.getMotherName());
                    familyVOMother.setRelationshipType("2");
                    familyVOMother.setCardType(enrollPre.getMotherCardType());
                    familyVOMother.setWork(enrollPre.getMotherWork());
                    familyVOMother.setCellphone(enrollPre.getMotherCellphone());
                }
                guardians.add(familyVOFather);
                guardians.add(familyVOMother);
                enrollPre.setFamilyList(guardians);
            }else{
                searchGuardians(enrollPre,familyList);
            }
        }
    }
    private void searchGuardians(EduStudentEnrollPreVO enrollPre,List<EduStudentEnrollFamily> familyList) {
        List<EduStudentEnrollFamilyVO> guardians = new ArrayList<>();
        if (!CollectionUtils.isEmpty(familyList)) {
            for (EduStudentEnrollFamily enrollFamily : familyList) {
                EduStudentEnrollFamilyVO familyVO=Convert.convert(EduStudentEnrollFamilyVO.class,enrollFamily);
                guardians.add(familyVO);
                if (RelationTypeEnum.father.getType().equals(enrollFamily.getRelationshipType())) {
                    enrollPre.setFatherIdcard(enrollFamily.getIdcard());
                    enrollPre.setFatherName(enrollFamily.getFullName());
                    enrollPre.setFatherCardType(enrollFamily.getCardType());
                    enrollPre.setFatherWork(enrollFamily.getWork());
                    enrollPre.setFatherCellphone(enrollFamily.getCellphone());
                } else if (RelationTypeEnum.mother.getType().equals(enrollFamily.getRelationshipType())) {
                    enrollPre.setMotherIdcard(enrollFamily.getIdcard());
                    enrollPre.setMotherName(enrollFamily.getFullName());
                    enrollPre.setMotherCardType(enrollFamily.getCardType());
                    enrollPre.setMotherWork(enrollFamily.getWork());
                    enrollPre.setMotherCellphone(enrollFamily.getCellphone());
                }else{
                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(enrollFamily.getHouseFlag())){
                        enrollPre.setRelationshipType(enrollFamily.getRelationshipType());
                        enrollPre.setRelationshipName(enrollFamily.getFullName());
                        enrollPre.setRelationshipIdcard(enrollFamily.getIdcard());
                        enrollPre.setRelationshipCardType(enrollFamily.getCardType());
                        enrollPre.setWork(enrollFamily.getWork());
                        enrollPre.setCellphone(enrollFamily.getCellphone());
                    }

                }
            }
        }
        enrollPre.setFamilyList(guardians);
    }
    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0011", title = "预报名管理获取网签数据", funcType = FuncTypeEnum.query)
    public void getWqByPreId(EduStudentEnrollPreKeyVO vo) {
        EduStudentEnrollPreVO preVO = this.getPreById(vo);

        //判断当前年度是否已报名
        Boolean flag = this.checkEnroll(preVO.getIdcard(), preVO.getYear());
        if (flag) {
            throw new AppException("已报名，不能同步网签数据");
        }
        if (StringUtils.isNotBlank(preVO.getIdcard())
                && StringUtils.isNotBlank(preVO.getFullName())) {
            NetsignSaveVO dygxVO = new NetsignSaveVO();
            dygxVO.setIdcard(preVO.getIdcard());
            dygxVO.setName(preVO.getFullName());
            dygxVO.setAreaCode(preVO.getAreaCode());
            dygxVO.setYear(preVO.getYear());
            dygxVO.setReplaceFlag(true);
            dygxVO.setReqIp(vo.getReqIp());
            eduNetsignIntegration.getNetsignAndSave(dygxVO);
        }
        if (StringUtils.isNotBlank(preVO.getFatherIdcard())
                && StringUtils.isNotBlank(preVO.getFatherName())) {
            NetsignSaveVO dygxVO = new NetsignSaveVO();
            dygxVO.setIdcard(preVO.getFatherIdcard());
            dygxVO.setName(preVO.getFatherName());
            dygxVO.setAreaCode(preVO.getAreaCode());
            dygxVO.setYear(preVO.getYear());
            dygxVO.setReplaceFlag(true);
            dygxVO.setReqIp(vo.getReqIp());
            eduNetsignIntegration.getNetsignAndSave(dygxVO);
        }
        if (StringUtils.isNotBlank(preVO.getMotherIdcard())
                && StringUtils.isNotBlank(preVO.getMotherName())) {
            NetsignSaveVO dygxVO = new NetsignSaveVO();
            dygxVO.setIdcard(preVO.getMotherIdcard());
            dygxVO.setName(preVO.getMotherName());
            dygxVO.setAreaCode(preVO.getAreaCode());
            dygxVO.setYear(preVO.getYear());
            dygxVO.setReplaceFlag(true);
            dygxVO.setReqIp(vo.getReqIp());
            eduNetsignIntegration.getNetsignAndSave(dygxVO);
        }
        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, preVO.getStudentEnrollPreId())
                .set(EduStudentEnrollPre::getNetsignSyncFlag, "1")
                .set(EduStudentEnrollPre::getNetsignSyncRemark, "调用成功");
        eduStudentEnrollPreService.update(updateWrapper);
        //清除缓存
        if(StringUtils.isNotBlank(preVO.getIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(preVO.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(preVO.getMotherIdcard());
        }
        if(StringUtils.isNotBlank(preVO.getFatherIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(preVO.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(preVO.getMotherIdcard());
        }
        if(StringUtils.isNotBlank(preVO.getMotherIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(preVO.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(preVO.getMotherIdcard());
        }
        eduEnrollClearCacheHelper.clearCachePreBefore(preVO.getStudentEnrollPreId());
    }

    private EduStudentEnrollPreVO getPreById(EduStudentEnrollPreKeyVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollPreId())) {
            throw new AppException("预采集id不能为空");
        }
        EduStudentEnrollPre eduStudentEnrollPre =
                eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
        EduStudentEnrollPreVO preVO = new EduStudentEnrollPreVO();
        BeanUtil.copyProperties(eduStudentEnrollPre, preVO, CopyOptions.create().ignoreCase());
        if (eduStudentEnrollPre == null) {
            throw new AppException("未找到预采集数据");
        }
        if (!AuthStatusEnum.YES.getType().equals(preVO.getAuthStatus())) {
            throw new AppException("该预采集未审核或者审核不通过");
        }
        Boolean singleParentFlag=false;
        if(StringUtils.isBlank(preVO.getMotherIdcard())){
            singleParentFlag=true;
        }
        if(StringUtils.isBlank(preVO.getFatherIdcard())){
            singleParentFlag=true;
        }
        preVO.setSingleParentFlag(singleParentFlag);
        if (StringUtils.isBlank(preVO.getCardType())) {
            preVO.setCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(preVO.getMotherCardType())) {
            preVO.setMotherCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(preVO.getFatherCardType())) {
            preVO.setFatherCardType(CardTypeEnum.idcard.getType());
        }
        return preVO;
    }

    private Boolean checkEnroll(String idcard, Integer year) {
        EduOperationCacheDetailVO eduOperationCacheDetailVO=operationCacheIntegration.getPeriodYear();
        Integer thisYear=eduOperationCacheDetailVO.getYear();
        if (year == null) {
            year=thisYear;
        }
        List<String> enrollStatusList = new ArrayList<>();
        enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
        QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
        enrollQueryWrapper.lambda().select(EduStudentEnroll::getIdcard).eq(EduStudentEnroll::getIdcard, idcard)
                .eq(EduStudentEnroll::getYear, year)
                .in(EduStudentEnroll::getEnrollStatus, enrollStatusList);
        if (eduStudentEnrollService.count(enrollQueryWrapper) <= 0) {
            return false;
        }
        return true;
    }
    public Boolean hasEnroll(String idcard, Integer year) {
        if(year==null){
            EduOperationCacheDetailVO eduOperationCacheDetailVO=operationCacheIntegration.getPeriodYear();
            year=eduOperationCacheDetailVO.getYear();
        }

        QueryWrapper<EduStudentEnroll> enrollQueryWrapper =new QueryWrapper<>();
        enrollQueryWrapper.lambda().select(EduStudentEnroll::getIdcard).eq(EduStudentEnroll::getIdcard,idcard)
                .eq(EduStudentEnroll::getYear,year);
        if(eduStudentEnrollService.count(enrollQueryWrapper)<=0){
            return false;
        }
        return true;
    }
    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0012", title = "预报名管理获取参保数据", funcType = FuncTypeEnum.query)
    public void getCbByPreId(EduStudentEnrollPreKeyVO vo) {
        EduStudentEnrollPreVO preVO = this.getPreById(vo);

        //判断当前年度是否已报名
        Boolean flag = this.checkEnroll(preVO.getIdcard(), preVO.getYear());
        if (flag) {
            throw new AppException("已报名，不能同步参保数据");
        }
        if (StringUtils.isNotBlank(preVO.getFatherIdcard())
                && StringUtils.isNotBlank(preVO.getFatherName())) {
            CbSaveVO dygxVO = new CbSaveVO();
            dygxVO.setIdcard(preVO.getFatherIdcard());
            dygxVO.setName(preVO.getFatherName());
            dygxVO.setYear(preVO.getYear());
            dygxVO.setAreaCode(preVO.getAreaCode());
            dygxVO.setReplaceFlag(true);
            dygxVO.setReqIp(vo.getReqIp());
            eduSocialSecurityIntegration.getSocialSecurityAndSave(dygxVO);
        }
        if (StringUtils.isNotBlank(preVO.getMotherIdcard())
                && StringUtils.isNotBlank(preVO.getMotherName())) {
            CbSaveVO dygxVO = new CbSaveVO();
            dygxVO.setIdcard(preVO.getMotherIdcard());
            dygxVO.setName(preVO.getMotherName());
            dygxVO.setYear(preVO.getYear());
            dygxVO.setAreaCode(preVO.getAreaCode());
            dygxVO.setReplaceFlag(true);
            dygxVO.setReqIp(vo.getReqIp());
            eduSocialSecurityIntegration.getSocialSecurityAndSave(dygxVO);
        }
        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, preVO.getStudentEnrollPreId())
                .set(EduStudentEnrollPre::getCbSyncFlag, "1")
                .set(EduStudentEnrollPre::getCbSyncRemark, "调用成功");
        eduStudentEnrollPreService.update(updateWrapper);
        //清除缓存
        if(StringUtils.isNotBlank(preVO.getIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreSb(preVO.getIdcard());
        }
        if(StringUtils.isNotBlank(preVO.getFatherIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreSb(preVO.getFatherIdcard());
        }
        if(StringUtils.isNotBlank(preVO.getMotherIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreSb(preVO.getMotherIdcard());
        }
        eduEnrollClearCacheHelper.clearCachePreBefore(preVO.getStudentEnrollPreId());
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0013", title = "预报名管理获取企业数据", funcType = FuncTypeEnum.query)
    public void getQyByPreId(EduStudentEnrollPreKeyVO vo) {
        EduStudentEnrollPreVO preVO = this.getPreById(vo);
        //判断当前年度是否已报名
        Boolean flag = this.checkEnroll(preVO.getIdcard(), preVO.getYear());
        if (flag) {
            throw new AppException("已报名，不能同步企业数据");
        }
        if (StringUtils.isNotBlank(preVO.getFatherIdcard())
                && StringUtils.isNotBlank(preVO.getFatherName())) {
            QySaveVO dygxVO = new QySaveVO();
            dygxVO.setIdcard(preVO.getFatherIdcard());
            dygxVO.setName(preVO.getFatherName());
            dygxVO.setAreaCode(preVO.getAreaCode());
            dygxVO.setYear(preVO.getYear());
            dygxVO.setReplaceFlag(true);
            eduCompanyIntegration.getCompanyAndSave(dygxVO);
        }
        if (StringUtils.isNotBlank(preVO.getMotherIdcard())
                && StringUtils.isNotBlank(preVO.getMotherName())) {
            QySaveVO dygxVO = new QySaveVO();
            dygxVO.setIdcard(preVO.getMotherIdcard());
            dygxVO.setName(preVO.getMotherName());
            dygxVO.setAreaCode(preVO.getAreaCode());
            dygxVO.setYear(preVO.getYear());
            dygxVO.setReplaceFlag(true);
            eduCompanyIntegration.getCompanyAndSave(dygxVO);
        }
        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, preVO.getStudentEnrollPreId())
                .set(EduStudentEnrollPre::getQySyncFlag, "1")
                .set(EduStudentEnrollPre::getQySyncRemark, "调用成功");
        eduStudentEnrollPreService.update(updateWrapper);
        //清除缓存
        if(StringUtils.isNotBlank(preVO.getIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreQy(preVO.getIdcard());
        }
        if(StringUtils.isNotBlank(preVO.getFatherIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreQy(preVO.getFatherIdcard());
        }
        if(StringUtils.isNotBlank(preVO.getMotherIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreQy(preVO.getMotherIdcard());
        }
        eduEnrollClearCacheHelper.clearCachePreBefore(preVO.getStudentEnrollPreId());
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0014", title = "预报名管理获取居住证数据", funcType = FuncTypeEnum.query)
    public void getJzzByPreId(EduStudentEnrollPreKeyVO vo) {
        EduStudentEnrollPreVO preVO = this.getPreById(vo);
        if (StringUtils.isNotBlank(preVO.getIdcard())
                && StringUtils.isNotBlank(preVO.getFullName())) {
            JzzSaveVO dygxVO = new JzzSaveVO();
            dygxVO.setIdcard(preVO.getIdcard());
            dygxVO.setName(preVO.getFullName());
            dygxVO.setAreaCode(preVO.getAreaCode());
            dygxVO.setYear(preVO.getYear());
            dygxVO.setLocalFlag(vo.getLocalFlag());
            dygxVO.setReplaceFlag(true);
            dygxVO.setReqIp(vo.getReqIp());
            eduLivePlaceIntegration.getLivePlaceAndSave(dygxVO);
        }
        if (StringUtils.isNotBlank(preVO.getFatherIdcard())
                && StringUtils.isNotBlank(preVO.getFatherName())) {
            JzzSaveVO dygxVO = new JzzSaveVO();
            dygxVO.setIdcard(preVO.getFatherIdcard());
            dygxVO.setName(preVO.getFatherName());
            dygxVO.setAreaCode(preVO.getAreaCode());
            dygxVO.setYear(preVO.getYear());
            dygxVO.setLocalFlag(vo.getLocalFlag());
            dygxVO.setReplaceFlag(true);
            dygxVO.setReqIp(vo.getReqIp());
            eduLivePlaceIntegration.getLivePlaceAndSave(dygxVO);
        }
        if (StringUtils.isNotBlank(preVO.getMotherIdcard())
                && StringUtils.isNotBlank(preVO.getMotherName())) {
            JzzSaveVO dygxVO = new JzzSaveVO();
            dygxVO.setIdcard(preVO.getMotherIdcard());
            dygxVO.setName(preVO.getMotherName());
            dygxVO.setAreaCode(preVO.getAreaCode());
            dygxVO.setYear(preVO.getYear());
            dygxVO.setLocalFlag(vo.getLocalFlag());
            dygxVO.setReplaceFlag(true);
            dygxVO.setReqIp(vo.getReqIp());
            eduLivePlaceIntegration.getLivePlaceAndSave(dygxVO);
        }
        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, preVO.getStudentEnrollPreId())
                .set(EduStudentEnrollPre::getJzzSyncFlag, "1")
                .set(EduStudentEnrollPre::getJzzSyncRemark, "调用成功");
        eduStudentEnrollPreService.update(updateWrapper);
        //清除缓存
        if(StringUtils.isNotBlank(preVO.getIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreJzz(preVO.getIdcard());
        }
        if(StringUtils.isNotBlank(preVO.getFatherIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreJzz(preVO.getFatherIdcard());
        }
        if(StringUtils.isNotBlank(preVO.getMotherIdcard())){
            eduEnrollClearCacheHelper.clearCacheMyEnrollPreJzz(preVO.getMotherIdcard());
        }
        eduEnrollClearCacheHelper.clearCachePreBefore(preVO.getStudentEnrollPreId());
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0015", title = "预报名管理重置比对错误数据", funcType = FuncTypeEnum.edit)
    public void resetError(BaseVO vo) {
        UpdateWrapper<EduStudentEnrollPre> ybm=new UpdateWrapper<>();
        ybm.lambda().set(EduStudentEnrollPre::getBeforeFlag,"0").eq(EduStudentEnrollPre::getBeforeFlag,"2");
        eduStudentEnrollPreService.update(ybm);
        //户籍
        UpdateWrapper<EduStudentEnrollPre> hj=new UpdateWrapper<>();
        hj.lambda().set(EduStudentEnrollPre::getHouseholdSyncFlag,"0").eq(EduStudentEnrollPre::getHouseholdSyncFlag,"2");
        eduStudentEnrollPreService.update(hj);
        //房产
        UpdateWrapper<EduStudentEnrollPre> fc=new UpdateWrapper<>();
        fc.lambda().set(EduStudentEnrollPre::getHouseSyncFlag,"0").eq(EduStudentEnrollPre::getHouseSyncFlag,"2");
        eduStudentEnrollPreService.update(fc);
        //出生证
        UpdateWrapper<EduStudentEnrollPre> csz=new UpdateWrapper<>();
        csz.lambda().set(EduStudentEnrollPre::getFamilyFlag,"0").eq(EduStudentEnrollPre::getFamilyFlag,"5");
        eduStudentEnrollPreService.update(csz);
        //企业
        UpdateWrapper<EduStudentEnrollPre> qy=new UpdateWrapper<>();
        qy.lambda().set(EduStudentEnrollPre::getQySyncFlag,"0").eq(EduStudentEnrollPre::getQySyncFlag,"2");
        eduStudentEnrollPreService.update(qy);
        //社保
        UpdateWrapper<EduStudentEnrollPre> sb=new UpdateWrapper<>();
        sb.lambda().set(EduStudentEnrollPre::getCbSyncFlag,"0").eq(EduStudentEnrollPre::getCbSyncFlag,"2");
        eduStudentEnrollPreService.update(sb);
        //居住证
        UpdateWrapper<EduStudentEnrollPre> jzz=new UpdateWrapper<>();
        jzz.lambda().set(EduStudentEnrollPre::getJzzSyncFlag,"0").eq(EduStudentEnrollPre::getJzzSyncFlag,"2");
        eduStudentEnrollPreService.update(jzz);
        //网签
        UpdateWrapper<EduStudentEnrollPre> wq=new UpdateWrapper<>();
        wq.lambda().set(EduStudentEnrollPre::getNetsignSyncFlag,"0").eq(EduStudentEnrollPre::getNetsignSyncFlag,"2");
        eduStudentEnrollPreService.update(wq);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0019", title = "预报名管理家庭关系比对", funcType = FuncTypeEnum.query)
    public String getFamInfoComparison(EduStudentEnrollPreKeyVO vo) {
        EduStudentEnrollPreVO preVO = this.getPreById(vo);
        String areaCode=preVO.getAreaCode();
        if(StringUtils.isBlank(areaCode)){
            areaCode=eduHelper.thisAreaCode();
        }
        ApiModel apiModel=eduHelper.getEduFunc("getFamInfoComparison",areaCode);
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                String str= (String) apiModel.getMethod().invoke(bean, vo);
                //清除缓存
                if(StringUtils.isNotBlank(preVO.getIdcard())){
                    eduEnrollClearCacheHelper.clearCacheMyEnrollPre(preVO.getIdcard());
                }
                if(StringUtils.isNotBlank(preVO.getFatherIdcard())){
                    eduEnrollClearCacheHelper.clearCacheMyEnrollPre(preVO.getFatherIdcard());
                }
                if(StringUtils.isNotBlank(preVO.getMotherIdcard())){
                    eduEnrollClearCacheHelper.clearCacheMyEnrollPre(preVO.getMotherIdcard());
                }
                if (StringUtils.isNotBlank(preVO.getStudentEnrollPreId())){
                    eduEnrollClearCacheHelper.clearCachePreBefore(preVO.getStudentEnrollPreId());
                }
                return str;
            }else {
                throw new AppException("未查询到方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (InvocationTargetException e ){
            try{
                AppException exception= (AppException) e.getTargetException();
                throw new AppException(exception.getMsg(),e.getTargetException());
            }catch (Exception ex){
                throw new AppException(e.getCause().getMessage(),e.getTargetException());
            }

        }catch (Exception e ){
            throw new AppException( e.getMessage(),e);
        }
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0020", title = "预报名管理单个可报名数据生成", funcType = FuncTypeEnum.edit)
    public int createEnrollBefore(EduStudentEnrollPreKeyVO vo) {
        if(StringUtils.isBlank(vo.getStudentEnrollPreId())){
            throw new AppException("预采集id不能为空");
        }
        EduStudentEnrollPre eduStudentEnrollPre=eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
        if(eduStudentEnrollPre==null){
            throw new AppException("未找到预采集数据");
        }
        String areaCode=eduStudentEnrollPre.getAreaCode();
        if(StringUtils.isBlank(areaCode)){
            areaCode=eduHelper.thisAreaCode();
        }
        ApiModel apiModel=eduHelper.getEduFunc("createEnrollBefore",areaCode);
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                Integer i= (Integer) apiModel.getMethod().invoke(bean, eduStudentEnrollPre);
                eduEnrollClearCacheHelper.clearCachePreBefore(eduStudentEnrollPre.getStudentEnrollPreId());
                return i;
            }else {
                throw new AppException("未查询到方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (InvocationTargetException e ){
            try{
                AppException exception= (AppException) e.getTargetException();
                throw new AppException(exception.getMsg(),e.getTargetException());
            }catch (Exception ex){
                throw new AppException(e.getCause().getMessage(),e.getTargetException());
            }

        }catch (Exception e ){
            throw new AppException( e.getMessage(),e);
        }
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0021", title = "预报名管理批量可报名数据生成", funcType = FuncTypeEnum.edit)
    @Async("commonTaskExecutor")
    public void createBatch(BatchCreateVO vo) {
        if (redisHelper.hasKey(createBatchBeforeCatch)) {
            throw new AppException("正在批量生成预报名数据中...");
        }
        redisHelper.set(createBatchBeforeCatch, "1", 7200);
        String areaCode=vo.getAreaCode();
        if(StringUtils.isBlank(areaCode)){
            areaCode=eduHelper.thisAreaCode();
        }
        ApiModel apiModel=eduHelper.getEduFunc("createBatch",areaCode);
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                apiModel.getMethod().invoke(bean, vo);
            }else {
                throw new AppException("未查询到方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (InvocationTargetException e ){
            try{
                AppException exception= (AppException) e.getTargetException();
                throw new AppException(exception.getMsg(),e.getTargetException());
            }catch (Exception ex){
                throw new AppException(e.getCause().getMessage(),e.getTargetException());
            }

        }catch (Exception e ){
            throw new AppException( e.getMessage(),e);
        }finally {
            redisHelper.del(createBatchBeforeCatch);
        }
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0024", title = "预报名管理可补报数重置生成状态", funcType = FuncTypeEnum.other)
    public void resetCreateBb(BatchCreateVO vo) {

    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0022", title = "预报名管理批量可报名数据生成缓存清除", funcType = FuncTypeEnum.other)
    public void clearCacheCreate(BaseVO vo) {
        redisHelper.del(createBatchBeforeCatch);
    }

    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0023", title = "预报名管理人员缓存清除", funcType = FuncTypeEnum.other)
    public void clearCachePre(EduStudentEnrollPreKeyVO vo) {
        EduStudentEnrollPre eduStudentEnrollPre;
        eduStudentEnrollPre = eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
        //如果正式表里面没有查询到，就去历史表查看
        if (eduStudentEnrollPre == null) {
            EduhStudentEnrollPre eduhStudentEnrollPre = eduhStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
            if (eduhStudentEnrollPre != null) {
                if ("1".equals(eduhStudentEnrollPre.getEncryptFlag())) {
                    if (StringUtils.isNotBlank(eduhStudentEnrollPre.getIdcard())) {
                        eduhStudentEnrollPre.setIdcard(CommonSecureUtil.sm4Decrypt(eduhStudentEnrollPre.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentEnrollPre.getFatherIdcard())) {
                        eduhStudentEnrollPre.setFatherIdcard(CommonSecureUtil.sm4Decrypt(eduhStudentEnrollPre.getFatherIdcard()));
                    }
                    if (StringUtils.isNotBlank(eduhStudentEnrollPre.getMotherIdcard())) {
                        eduhStudentEnrollPre.setMotherIdcard(CommonSecureUtil.sm4Decrypt(eduhStudentEnrollPre.getMotherIdcard()));
                    }
                }
                eduStudentEnrollPre = Convert.convert(EduStudentEnrollPre.class, eduhStudentEnrollPre);
            }else {
                throw new AppException("没有找到数据，请重试");
            }
        }

        eduEnrollClearCacheHelper.clearAll(eduStudentEnrollPre.getIdcard());
        eduEnrollClearCacheHelper.clearAll(eduStudentEnrollPre.getFatherIdcard());
        eduEnrollClearCacheHelper.clearAll(eduStudentEnrollPre.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCachePreBefore(vo.getStudentEnrollPreId());
    }

    @Override
    @Transactional
    @OpApi(funcCode = "eduStudentEnrollBefore0026", title = "修改代理报名状态", funcType = FuncTypeEnum.update)
    public void updateAgentEnrollFlag(EduAgentEnrollVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollPreId())) {
            throw new AppException("预采集id不能为空");
        }
        EduStudentEnrollPre studentEnrollPre = eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
        if (ObjectUtils.isEmpty(studentEnrollPre)){
            throw new AppException("未找到预采集数据");
        }
        if (StringUtils.isBlank(vo.getAgentEnrollFlag())) {
           vo.setAgentEnrollFlag(BoolEnum.FALSE.getType());
        }
        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, vo.getStudentEnrollPreId())
                .set(EduStudentEnrollPre::getAgentEnrollFlag, vo.getAgentEnrollFlag());
        eduStudentEnrollPreService.update(updateWrapper);
        //清除缓存
        EduStudentEnrollPreKeyVO keyVO = new EduStudentEnrollPreKeyVO();
        keyVO.setStudentEnrollPreId(studentEnrollPre.getStudentEnrollPreId());
        this.clearCachePre(keyVO);
    }


    private void setPersonId(EduStudentEnrollPreVO vo) {
        PersonInfo stuPersonInfo =
                this.savePerson(vo.getIdcard(), vo.getCardType(), vo.getFullName());
        vo.setPersonId(stuPersonInfo.getPersonId());
        if (!ObjectUtils.isEmpty(vo.getMotherIdcard())) {
            PersonInfo moPersonInfo =
                    this.savePerson(
                            vo.getMotherIdcard(), vo.getMotherCardType(), vo.getMotherName());
            vo.setMotherId(moPersonInfo.getPersonId());
        }
        if (!ObjectUtils.isEmpty(vo.getFatherIdcard())) {
            PersonInfo faPersonInfo =
                    this.savePerson(
                            vo.getFatherIdcard(), vo.getFatherCardType(), vo.getFatherName());
            vo.setFatherId(faPersonInfo.getPersonId());
        }
    }

    private PersonInfo savePerson(String idcard, String cardType, String fullName) {
        if (StringUtils.isBlank(cardType)) {
            cardType = CardTypeEnum.idcard.getType();
        }
        if(!CardTypeEnum.idcard.getType().equalsIgnoreCase(cardType)){
            if(IdcardUtil.isValidCard(idcard)){
                cardType= CardTypeEnum.idcard.getType();
            }
        }
        PersonInfo personInfo =
                personInfoService.selectByCardTypeAndIdcard(cardType, StringUtils.upperCase(idcard));
        if (personInfo == null) {
            QueryWrapper<PersonInfo> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(PersonInfo::getIdcard, idcard);
            List<PersonInfo> list = personInfoService.list(queryWrapper);
            if (!CollectionUtils.isEmpty(list)) {
                personInfo = list.get(0);
            }
        }
        if (ObjectUtils.isEmpty(personInfo)) {
            personInfo = new PersonInfo();
            personInfo.setIdcard(StringUtils.upperCase(idcard));
            personInfo.setFullName(fullName);
            personInfo.setCardType(cardType);
            return personInfoService.addPerson(personInfo);
        } else {
            if (!personInfo.getFullName().equals(fullName)||!personInfo.getCardType().equals(cardType)) {
                personInfo.setFullName(fullName);
                personInfoService.updateById(personInfo);
            }
            return personInfo;
        }
    }

    private String saveDict(String dictField, String dictValue, String accessToken) {
        if (ObjectUtils.isEmpty(dictValue)) {
            return dictValue;
        }
        DictQueryVO dictQueryVO = new DictQueryVO();
        dictQueryVO.setDictField(dictField);
        dictQueryVO.setDictValue(dictValue);
        String key = dictIntegration.getKey(dictQueryVO);
        if (!ObjectUtils.isEmpty(key)) {
            return key;
        } else {
            List<SelectVO> dictList = dictIntegration.getDictByDictField(dictQueryVO);
            int maxKey =
                    dictList.stream()
                            .mapToInt(item -> Integer.parseInt(item.getDictKey()))
                            .max()
                            .getAsInt();
            DictVO dictVO = Convert.convert(DictVO.class, dictList.get(0));
            dictVO.setSysId(null);
            dictVO.setDictKey(maxKey + 1 + "");
            dictVO.setDictValue(dictValue);
            dictVO.setAccessToken(accessToken);
            dictIntegration.add(dictVO);
            return dictVO.getDictKey();
        }
    }

}
